Getting a 400 - bad request when sending an xmlhttp to a wcf using vbscript
we are getting an 400/bad Request when we send a request. Please find our code below.
Public Sub test123()
URL = "http://dev1.xxxxx.employer/employer/v02/Employer.svc"
Dim requestDoc
Set requestDoc = CreateObject("MSXML2.DOMDocument.3.0")
Dim root
Set root = requestDoc.createNode(1, "Envelope", "http://schemas.xmlsoap.org/soap/envelope/")
requestDoc.appendChild root
Dim nodeBody
Set nodeBody = requestDoc.createNode(1, "Body", "http://schemas.xmlsoap.org/soap/envelope/")
root.appendChild nodeBody
Dim nodeOp
Set nodeOp = requestDoc.createNode(1, "Register", "http://xxxxx.com/Employer/Contracts/v2")
nodeBody.appendChild nodeOp
Dim nodeRequest
Set nodeRequest = requestDoc.createNode(1, "request", "http://xxxxx.com/Employer/Contracts/v2")
'content of the request will vary depending on the WCF Service.'
' This one takes just a plain string. '
Dim sv_strTempxml As Variant
sv_strTempxml1 = "<CreateProspectRequest xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">" _
& "<Employer><PartyDisplayName>0707 NS2 DEV1 KRISH 001</PartyDisplayName><PreferredLanguageIdentifier xsi:nil=""true"" />" _
& "<PartyIdentifier xsi:nil=""true"" /><PartyAddresses><PartyAddressStructure><BeginTimeStamp xsi:nil=""true"" /><CityName>Alexander City</CityName>" _
& "<CountryCode>US</CountryCode><EndTimeStamp xsi:nil=""true"" /><FirstLineAddress>111 Main Street</FirstLineAddress><PostalCode>35010</PostalCode>" _
& "<SecondJurisdictionCode>AL</SecondJurisdictionCode><SecondJurisdictionTypeCode>ST</SecondJurisdictionTypeCode><SecondLineAddress>PL</SecondLineAddress><AddressIdentifier xsi:nil=""true"" />" _
& "<PartyIdentifier xsi:nil=""true"" /><AddressUsageIdentifier>100000</AddressUsageIdentifier><SecondJurisdiction>1</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>0707 NS2 DEV1 KRISH 001</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>"
nodeRequest.Text = sv_strTempxml1
nodeOp.appendChild nodeRequest
Set nodeRequest = Nothing
Set 开发者_如何学JAVAnodeOp = Nothing
Set nodeBody = Nothing
Set root = Nothing
'MsgBox "sending request " & vbCrLf & requestDoc.XML
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP.3.0")
' set the proxy as necessary and desired '
'xmlhttp.setProxy 2, "http://localhost:8888"
xmlhttp.Open "POST", URL, False
' set SOAPAction as appropriate for the operation '
xmlhttp.setRequestHeader "SOAPAction", "http://xxxxx.com/Employer/Contracts/v2/Employer/CreateProspect"
xmlhttp.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8"
xmlhttp.send requestDoc.XML
' vbCrLf & "Raw XML response:" & vbCrLf
MsgBox xmlhttp.responseXML.XML
End Sub
is there any item we have missed out
Santhosh
What binding(s) is your WCF service exposed over? If you're using the WsHttpBinding
, you're probably going to have to use https
.
If the service is using a BasicHttpBinding
, then http
should be fine, but you'll need to change the Content-Type to text/xml
.
Update
The reason I say this is that I've used Visual Studio WebTests to send SOAP XML to WCF services. When accessing Basic HTTP endpoints, it only works if I use text/xml
. Maybe you need to put the SOAP Header stuff in the XML. Here's what I've used successfully in the past:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header>
<a:Action s:mustUnderstand="1">[ACTION]</a:Action>
<a:To s:mustUnderstand="1">[ADDRESS]</a:To>
</s:Header>
<s:Body>
...
</s:Body>
</s:Envelope>
精彩评论