我正在使用我們的票務系統OTRS中的SOAP web服務。所以Webservice並不是真的在我的控制之下。 該請求的工作很好,但我從來沒有得到我的代碼中的答案。答案始終爲空。 (var response = client.SessionCreate(session);
) 奇怪的是,那個票務系統的wireshark和webservice控制檯說我應該收到一個有效的答案。 由於我對這個web服務的東西很新,所以我絕對不知道從哪裏開始在這種情況下。所以這裏是對我的描述。任何建議真的很感激。WCF Webservice總是返回null
首先,我創建了一個正常的C#項目,並添加了只能在OTRS項目的GitHub站點網站上找到的WSDL文件。我將它添加爲Service Reference,並添加了看起來像這樣的C#代碼。
//用於調試 System.Net.ServicePointManager.Expect100Continue = false; Thread.CurrentThread.CurrentUICulture = new CultureInfo(「en-us」);在服務器端
try
{
OTRS.OTRS_Error err = new OTRS.OTRS_Error();
OTRS.GenericTicketConnector_PortTypeClient client = new OTRS.GenericTicketConnector_PortTypeClient("GenericTicketConnector_Port");
OTRS.SessionCreate session = new OTRS.SessionCreate();
session.Item = "someUserNameGoesHere";
session.ItemElementName = OTRS.ItemChoiceType8.UserLogin;
session.Password = "SomePasswordGoesHere";
var response = client.SessionCreate(session);
Console.WriteLine(response.SessionID);
Console.WriteLine(response.Error);
}
catch (Exception exep)
{
Console.WriteLine(exep.Message);
Console.WriteLine(exep.InnerException);
}
finally
{
Console.ReadLine();
}
傳入消息
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">http://www.otrs.org/TicketConnector/SessionCreate</a:Action>
<a:MessageID>urn:uuid:14750529-3de2-4618-8db4-8ac18b681c18</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">http://SomeServer/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnector</a:To>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SessionCreate xmlns="http://www.otrs.org/TicketConnector/">
<UserLogin xmlns="">someUserName</UserLogin>
<Password xmlns="">somePassword</Password>
</SessionCreate>
</s:Body>
在服務器端
傳出消息
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<SessionCreateResponse xmlns="http://www.otrs.org/TicketConnector/">
<SessionID>SomeSessionID</SessionID>
</SessionCreateResponse>
</soap:Body>
</soap:Envelope>
Wireshark的HTTP/XML包從服務器將我的客戶
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<SessionCreateResponse xmlns="http://www.otrs.org/TicketConnector/">
<SessionID>SomeSessionID</SessionID>
</SessionCreateResponse>
</soap:Body>
</soap:Envelope>
Refernce.cs https://gist.github.com/HansVader/1ba3847d918ee15ef16703c8ada6c9bf
WSDL https://gist.github.com/HansVader/dd849e49f4a1584397cd21b0e430b301
我目前只需要SessionnCreate和TicketUpdate功能。其他操作在這個時間點是無關緊要的。如果您需要其他信息,請告訴我。
更新:
我想這也是值得注意的是,我所創造的refernce.cs
我自己與svcutil
工具,因爲我有一個IsWrapped的問題。看看這個問題,回答: XmlSerializer attribute not valid in Web Service using WCF
您是否嘗試過WCF跟蹤? https://msdn.microsoft.com/en-us/library/ms751526.aspx –
它看起來像你發送的消息是正確的,你收到的消息。我檢查了一下命名空間,看起來好像一見鍾情。但是,反序列化似乎並不奏效,所以可能是WSDL產生錯誤,或者WSDL錯誤。您是否嘗試多次添加服務引用(添加和刪除),或者在reference.cs中更改了任何內容? – Cosmin
建議你看看ServiceStack.net - 非常棒的web服務庫。他們的下載頁面底部有一個較舊的開源版本。 –