views:

70

answers:

1

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""&gt;" _
   & "<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 nodeOp = 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

A: 

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"&gt;
    <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>
Graham Clark
its using the basic Http binding, and when i change the Content-type to text/xml i am getting an error stating that the Content type should be "application/soap+xml"
hmm, that's weird, this is what I've used in the past. I've updated my answer with some more details...
Graham Clark