我在 C# 中有一個應用程式然后我必須給出如下請求的結果。
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Body>
<MyAppResponse xmlns="http://www.specificAddress.com">
<MyAppResult xmlns:abc1="http://schemas.specificAddress.Responses" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<abc1:ResponseData xmlns:aef2="http://schemas.datacontract.org/Test.GenericMerchantServices.Classes.Domain">
<aef2:ResponseCode>0000</aef2:ResponseCode>
<aef2:ResponseDescription>Successful</aef2:ResponseDescription>
</abc1:ResponseData>
</MyAppResult>
</MyAppResponse>
</s:Body>
</s:Envelope>
在這種情況下,我使用 .NET 5 應用程式和 soapCore 在 .NET Core 中使用 soap。這是我的介面和派生類。
[ServiceContract]
public interface IMyAppService
{
[OperationContract]
MyAppResult MyApp(MyAppRequest request);
}
public class MyAppService : IMyAppService
{
public MyAppResult MyApp(MyAppRequest request)
{
return new MyAppResult()
{
ResponseData = new ResponseData()
{
ResponseCode = "0000",
ResponseDescription = "Test "
}
};
}
}
我嘗試使用資料注釋更新命名空間,但我不知道如何更新前綴并按要求做出回應。這是我的課
[XmlRoot(Namespace = "http://schemas.specificAddress.Responses")]
public class MyAppResult
{
[XmlElement(ElementName = "ResponseData", Namespace = "http://schemas.datacontract.org/Test.GenericMerchantServices.Classes.Domain")]
public ResponseData ResponseData { get; set; }
}
public class ResponseData
{
public string ResponseCode { get; set; }
public string ResponseDescription { get; set; }
}
當我使用這個端點時,我得到了這個結果。
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<s:Body>
<MyAppResponse xmlns="http://tempuri.org/">
<MyAppResult xmlns="http://schemas.specificAddress.Responses" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ResponseData xmlns="http://schemas.datacontract.org/Test.GenericMerchantServices.Classes.Domain">
<ResponseCode>0000</ResponseCode>
<ResponseDescription>Test </ResponseDescription>
</ResponseData>
</MyAppResult>
</MyAppResponse>
</s:Body>
</s:Envelope>
問題是如何向我的專案添加 ns 和自定義前綴,以及如何在 myappresponse 上添加自定義命名空間。
uj5u.com熱心網友回復:
要更改 WCF 服務的命名空間,您需要將 Namespace 屬性應用于服務協定介面上的 ServiceContractAttribute。詳細資訊可以在http://blog.rebuildall.net/2010/11/10/WCF_service_namespaces
中找到。
關于添加前綴可以看一下這個檔案。
XML 序列化和命名空間前綴
C# WCF 全域命名空間 - Royal Mail
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/424804.html
上一篇:Global.asax.csApplication_BeginRequest-拋出WebFaultException
