0

嗨,我是 wcf 和 xmlhttp 的新手,我正在使用 vb 脚本发送请求。我收到以下错误“无法处理消息,因为内容类型 'text/xml; charset=UTF-8' 不是预期的类型 'application/soap+xml; charset=utf-8'。”

请在下面找到我的代码,

g_XMLLink = "http://dev1.xxxxx.employer/employer/v02/Employer.svc"
Set xmlhttp = Nothing
Set xmldom = Nothing '
Set xmlhttp = CreateObject("Microsoft.XMLHTTP")
Set xmldom = CreateObject("Microsoft.XMLDOM")

completexml = "<CreateProspectRequest xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><Employer><PartyDisplayName>cbs1a test</PartyDisplayName><PreferredLanguageIdentifier xsi:nil='true' /><PartyIdentifier xsi:nil='true' /><PartyAddresses>" _
& "<PartyAddressStructure><BeginTimeStamp xsi:nil='true' /><CityName>portland</CityName><CountryCode>US</CountryCode><EndTimeStamp xsi:nil='true' /><FirstLineAddress>congress street</FirstLineAddress><PostalCode>04102</PostalCode><SecondJurisdictionCode>ME</SecondJurisdictionCode><SecondJurisdictionTypeCode>ST</SecondJurisdictionTypeCode>" _
& "<SecondLineAddress /><AddressIdentifier xsi:nil='true' /><PartyIdentifier xsi:nil='true' /><AddressUsageIdentifier>100000</AddressUsageIdentifier><SecondJurisdiction>20</SecondJurisdiction><ChangeTypeCode xsi:nil='true' /></PartyAddressStructure></PartyAddresses>" _
& "<PreferredLanguage>100</PreferredLanguage><ChangeTypeCode xsi:nil='true' /><PartyTypeIdentifier xsi:nil='true' /><EstablishedDate xsi:nil='true' /><OrganizationTypeIdentifier>100018</OrganizationTypeIdentifier><OrganizationNames><OrganizationNameStructure><NameEndTimestamp xsi:nil='true' />" _
& "<NameStartTimestamp xsi:nil='true' /><OrganizationPartyName>cbs1a test</OrganizationPartyName><NameTypeIdentifier>1</NameTypeIdentifier><PartyIdentifier xsi:nil='true' /><ChangeTypeCode xsi:nil='true' /></OrganizationNameStructure></OrganizationNames><ProspectReceivedDate xsi:nil='true' />" _
& "<RatingGroupIdentifier xsi:nil='true' /></Employer><AffiliationCode>UUS</AffiliationCode></CreateProspectRequest>"

xmlhttp.Open "POST", g_XMLLink, False
xmlhttp.setRequestHeader "ContentType", "text/xml; charset=utf-8"
xmlhttp.setRequestHeader "SoapAction", "http://xxxxx.com/Employer/Contracts/v2/Employer/CreateProspect"


xmldom.loadXML completexml
xmlhttp.send xmldom
MsgBox xmlhttp.responseText
4

2 回答 2

2

几乎每次我都收到错误

type 'text/xml; charset=UTF-8' was not the expected type 'application/soap+xml; charset=utf-8'."

这是因为服务器返回了错误页面,而不是对 WCF 调用的响应。

您需要记录响应以查看错误消息是什么。

于 2010-09-03T13:24:16.537 回答
1

您确定要发送 SOAP 请求吗?我在您的请求中没有看到任何 soap:Envelope 或 soap:Body 元素。您的内容类型问题可能是基于您正在发送 text/xml 但服务器需要 application/soap+xml 的事实。当您尝试将 SOAP 1.1 请求发送到需要 SOAP 1.2 的服务时,就会发生这种情况。

于 2010-09-03T14:01:48.540 回答