【发布时间】:2012-08-02 13:36:53
【问题描述】:
我使用从 Visual Studio 2010 生成的 Web 服务代理类从我的 .net 2.0 客户端访问 Web 服务。
这一切正常,但我的问题是,Web 服务有一个用于测试系统的 wsdl 和一个用于生产系统的 wsdl。
虽然 Web 服务在结构上完全相同,但它们的 xml 命名空间却不同。
在我的代码中,我可以设置 web 服务的服务 URL 并且通信正常(我使用 TraceExtension 将 SOAP 消息转储到日志文件),但是在反序列化时,我得到了一个异常。
我认为这是因为我使用来自测试系统的 WSDL 文件生成了代理类,并添加了如下几个属性: [System.Xml.Serialization.SoapTypeAttribute(Namespace="testservice url here")]
我当然可以复制我的项目并向生产服务添加网络引用,但这会复制我的代码,并且我必须在未来在两个项目中进行任何进一步的更改,这当然容易出错。
这是针对测试系统服务调用登录方法的有效响应:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://TEST_SERVER_NAME/ProjectService">
<SOAP-ENV:Body>
<ns1:loginResponse xmlns:ns1="http://TEST_SERVER_NAME/ProjectService">
<login_result xsi:type="tns:LoginResult">
<errorcode xsi:type="xsd:integer">0</errorcode>
<errortext xsi:type="xsd:string">Successfully logged in</errortext>
<logincode xsi:type="xsd:string">wF3N5vdPsueL0aYlp41i6B8VTZEJztqx</logincode>
</login_result>
</ns1:loginResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
这是来自生产网络服务的相同响应:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://PRODUCTION_SERVER_NAME/ProjectService">
<SOAP-ENV:Body>
<ns1:loginResponse xmlns:ns1="http://TEST_SERVER_NAME/ProjectService">
<login_result xsi:type="tns:LoginResult">
<errorcode xsi:type="xsd:integer">0</errorcode>
<errortext xsi:type="xsd:string">Successfully logged in</errortext>
<logincode xsi:type="xsd:string">wOmdlZMkIXVL4H8uTGU69hgpNsK1Cz3Q</logincode>
</login_result>
</ns1:loginResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
如您所见,两个响应仅在 xmlns:tns 属性上有所不同,而 xmlns:ns1 属性始终为http://TEST_SERVER_NAME/ProjectService(我猜这是来自带有测试系统的 WSDL 的生成代理类) .
登录码只是一个身份验证令牌,并且总是不同的,所以没关系。
这个问题还有其他解决办法吗?
【问题讨论】:
标签: c# visual-studio-2010 web-services wsdl proxy-classes