2010-11-08 66 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