C#WebService中的空参数
我收到了一个必须实现的Web服务的WSDL,并从中生成了它的基本结构(使用.NET SDK中的svcutils.exe和Visual Studio的WSDL.blue插件进行了尝试)。有人将使用此Web服务,我无法更改他们的请求类型。下面是我从客户机捕获的SOAP请求示例:C#WebService中的空参数,c#,visual-studio,web-services,soap,C#,Visual Studio,Web Services,Soap,我收到了一个必须实现的Web服务的WSDL,并从中生成了它的基本结构(使用.NET SDK中的svcutils.exe和Visual Studio的WSDL.blue插件进行了尝试)。有人将使用此Web服务,我无法更改他们的请求类型。下面是我从客户机捕获的SOAP请求示例: <env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'> <env:Header></env:Header>
<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>
这是我的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;
}
[System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“4.0.30319.233”)]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute(“代码”)]
[System.Xml.Serialization.XmlTypeAttribute(命名空间=”http://client.response.ws.na.agorang.ptinovacao.pt/")]
公共部分类OrderResponse
{
///
[System.Xml.Serialization.xmlementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
公共字符串messageID;
///
[System.Xml.Serialization.xmlementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
公共订单头订单头;
///
[System.Xml.Serialization.xmlementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
公共字符串信息;
}
还定义并实现了所需的类(OrderResponse等)。您知道我可以在代码中更改什么(因为我无法更改客户机的请求,使其在OrderResponse上具有ns1名称空间)以使其能够接受SOAP请求吗?
谢谢 OrderResponse类上的
XmlTypeAttribute
行是Web服务要求在特定命名空间中存在的原因。为了解决这个问题,我非常确定您可以从文件中删除这行代码
但是,从生成的代码中删除这一行并不是最佳的解决方案,因为从WSDL中重新生成将把这一行放回代码中。理想情况下,您可以修改WSDL,以便将元素定义为存在于一个空白的目标命名空间中。您可以向我们展示
OrderResponse
类的定义吗?当然,我已经将其添加到了原始的post中。不,即使我删除了XmlTypeAttribute,如果没有命名空间,参数也无法识别。
[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;
}