我正在尝试使用我们的会员数据库服务 (iMIS) 提供的 Web 服务。
这是在他们的网站上使用 WSDL 的示例。
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://www.atsol.org/webservices_demo/wscontacts.asmx/");
var c = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("Username", "myname"),
new KeyValuePair<string, string>("Password", "mypassword"),
new KeyValuePair<string, string>("UpdateLoggedInDate", "false")
});
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
LoginResultsWithData r = response.Result.Content.ReadAsAsync<LoginResultsWithData>().Result;
它工作正常,但是当它到达最后一行并尝试将 XML 反序列化为“LoginResultsWithData”对象时,它会在名称空间上遇到错误。
第 1 行位置 163 出错。来自命名空间“ http://schemas.datacontract.org/2004/07/myProjectName.iMISCONTACTService ”的预期元素“LoginResultsWithData” 。遇到名称为“LoginResultsWithData”的“元素”,命名空间“ http:/ /www.atsol.org/wsContacts/ '。
这是来自网络服务的响应
HTTP/1.1 200 OK
Date: Wed, 17 Jul 2013 19:48:59 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Content-Length: 1202
<?xml version="1.0" encoding="utf-8"?>
<LoginResultsWithData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.atsol.org/wsContacts/">
<ResultCode>#</ResultCode>
<ResultMessage>Succeeded</ResultMessage>
<ID>####</ID>
<InstituteContactId>####</InstituteContactId>
<IsMember>false</IsMember>
<IsInstitute>false</IsInstitute>
<CustomerTypeCode>S</CustomerTypeCode>
<BillingCategory />
<ContactStatusCode>A</ContactStatusCode>
<PaidThruDate>2099-12-31T00:00:00</PaidThruDate>
<FullName>My Name</FullName>
<FirstName>My</FirstName>
<LastName>Name</LastName>
<Informal>My</Informal>
<Roles />
<IMISCookies>
<IMISCookie>
<CookieName>ASP.NET_SessionId</CookieName>
<CookieValue>io0um25qmae35wiogsjgwrsq</CookieValue>
</IMISCookie>
<IMISCookie>
<CookieName>Login</CookieName>
<CookieValue>34E1A645EB3F4AE693EDEE665D2328264C7F064B366DE16286DF83E6D79AF7663294E1275DA22703506F3E8E3F89D02C27DAB30F2D6A4A43A3AF1A6D0DCD1A2AFDFD18073E6187111430228892A9C7EC</CookieValue>
</IMISCookie>
</IMISCookies>
</LoginResultsWithData>
在你问之前,不,我不能搞乱网络服务。帮助?!