我被交給了一個WebService的WSDL,我必須實現它並從中生成它的基本結構(使用.NET SDK的svcutils.exe和Visual Studio的WSDL.blue插件進行嘗試)。有人會使用這個WebService,我不能改變他們所做的請求的類型。下面是一個示例SOAP請求我從我的客戶捕捉:C#WebService中的空參數
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Header></env:Header>
<env:Body>
<ns1:setNetworkActivatorResponse xmlns:ns1='http://client.response.ws.meh/'>
<OrderResponse>
<orderHeader>
<clientID>trD-125205</clientID>
<description>0</description>
<operation>trD</operation>
<orderKey>
<applicationContext>
<URL>http://xxx.xxx.xxx.xxx:8181/</URL>
<hostName>xxx.xxx.xxx.xxx</hostName>
</applicationContext>
<applicationDN>XYPT</applicationDN>
<primaryKey>170809</primaryKey>
</orderKey>
<priority>1</priority>
</orderHeader>
<info>
Yadda Yadda Yadda text.
</info>
</OrderResponse>
</ns1:setNetworkActivatorResponse>
</env:Body>
</env:Envelope>
此請求調用(setNetworkActivatorResponse()),但是該方法的參數OrderResponse作爲空通過在Web服務器上正確的方法。我相信它與名稱空間有關,因爲如果我修改請求並將ns1名稱空間添加到OrderResponse(如<ns1:OrderResponse> </ns1:OrderResponse>
),則參數會正確傳遞,並且OrderResponse對象在C#方法中可用。
我的方法是定義爲典型的C#.NET的WebService:
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[WebService(Namespace = "http://client.response.ws.meh/")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://client.response.ws.meh/")]
[System.ServiceModel.ServiceContractAttribute(Namespace = "http://client.response.ws.meh/", ConfigurationName = "ResponseClientWebService")]
public class ResponseClientWebService : System.Web.Services.WebService
{
[WebMethod]
public void setNetworkActivatorResponse(OrderResponse OrderResponse)
{
String meh = OrderResponse.info;
}
}
這裏是我的OrderResponse類:定義和實現
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://client.response.ws.na.agorang.ptinovacao.pt/")]
public partial class OrderResponse
{
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string messageID;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public OrderHeader orderHeader;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string info;
}
所需的類(OrderResponse和這樣)好。任何想法我可以在我的代碼中改變(看到我無法更改客戶端的請求,讓OrderResponse上的ns1命名空間)使它能夠接受SOAP請求? 謝謝!
你能告訴我們'OrderResponse'類的定義嗎? – pmartin
當然,我已將它添加到原始帖子。 –