2010-11-08 76 views
1

我有一个.NET 4.0 Web服务,其中有一个targetNamespace为“http://tempuri.org”WSDL生成时。客户向我发送一个xmlns设置为“uri:company:agent”的SOAP信封(请参阅下面的示例)由于命名空间不同,我的服务拒绝SOAP信封。WSDL Xmlns更改

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:company:agent"> 
<SOAP-ENV:Body> 
    <ns1:send_message xmlns="urn:company:agent"> 
     <item1>abc</item1> 

我收到以下错误:

<faultstring xml:lang="en-US">Error in deserializing body of request message for operation 'send_message'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'send_message' and namespace 'http://tempuri.org/'. Found node type 'Element' with name 'ns1:send_message' and namespace 'urn:company:agent'</faultstring> 

我的问题是:我找不到在哪里改的Visual Studio 2010中我的项目的命名空间,以反映“URI:公司:代理商“而不是”http://tempuri.org/“。我已经看过很多,但是我所做的任何更改都没有反映在WSDL中。

回答

1

如果lookt在你的.asmx代码文件应该开始是这样的:

[WebService(Namespace = "http://tempuri.org")] 
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
[System.ComponentModel.ToolboxItem(false)] 
public class YourServiceName: WebService 
{ 

只要改变tempuri.org网址在那里。如果你的名字空间没有在那里声明,你可以声明它,我认为tempuri可能是默认的。

如果您使用的是WCF,则会略有不同。你会想看看你的.svc文件的顶部,可能需要添加这样的ServiceBehavior声明:

[ServiceBehavior(Name = "MyService", Namespace = "http://myservice.com/")] 
public class Service1 : IService1 
{ 
+0

..我想我可以在上面输错....我有一个。 svc文件不是asmx文件。这会有所作为吗? – 2010-11-08 16:03:53

+0

更新了我的答案,第二部分应该适合你。 – brendan 2010-11-08 16:14:10

+0

谢谢!这是我必须添加到每种方法吗?我添加了服务行为,但现在所有的公共方法现在在WSDL中更长时间可见了? – 2010-11-08 16:34:07