הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Saturday, April 11, 2015 3:47 PM
So I have been trying to find an answer for this for a couple weeks. Hopefully I can get an answer here. I am new to Web Services so I am not sure if my question is being asked correctly, but here is goes.
When I use SOAPUI and send a request with the username parameter, I was getting the information back. When I call the same request in VB .NET I would get an error back from the Web server. "Internal Error <client>"
We found that VB.NET is adding this "xsi:type="xsd.string" in the <username> brackets. The clients server does not like this. The code is below. First what SOAPUI is sending and the second is what VB is sending. How do I stop the VB from adding the extra line?
THIS IS THE SOAPUI. This works
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<q1:GetEmailFromUsername xmlns:q1="http://MyServer.com>
<Username>MyName</Username>
</q1:GetEmailFromUsername>
</soap:Body>
This is what VB is sending . This does not work<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<q1:GetEmailFromUsername xmlns:q1="http://MyServer.com>
<Username xsi:type="xsd.string">MyName</Username>
</q1:GetEmailFromUsername>
</soap:Body>
All replies (11)
Saturday, April 11, 2015 4:08 PM
Can you add Catch block with the below and send us the result please:
Try
'Your webservice call
Catch e As SoapException
Console.WriteLine("SOAP Exception Error Code: {0}", e.SubCode.Code.Name)
Console.WriteLine("SOAP Exception Message is: {0}", e.Message)
End Try
Fouad Roumieh
Saturday, April 11, 2015 4:31 PM
Maybe I should also add that this call works
strResult = MyService.GetAllProgramNames() 'Returns all the info
But any call I make where I send a parameter it fails like this call
strResult = MyService.GetEmailFromUsername(strUserName.Trim)
I got this back.
A first chance exception of type 'System.Web.Services.Protocols.SoapHeaderException' occurred in System.Web.Services.dll
SOAP Exception Error Code: Client
SOAP Exception Message is: Internal Error (from client)
Saturday, April 11, 2015 4:39 PM
Can you change the method GetEmailFromUsername to just take a parameter and return a static string value on the first line and see what happens? I mean don't do any processing inside the method.
Fouad Roumieh
Saturday, April 11, 2015 4:49 PM
I apologize, but I am not quite sure what you are asking me to do. If you are asking me to change something on the server side I am unable to. It is a cutomers server and I do not have access to their server to change anything.
Saturday, April 11, 2015 4:51 PM
Ok I didn't know that, can you post the wsdl(at least for that method) and the full code of the request? Do you pass any credentials when calling this service?
Fouad Roumieh
Saturday, April 11, 2015 5:01 PM | 1 vote
How did you create the service reference in VB? From Add -> Service Reference? If you click the advanced button when adding the reference you get several options. You can make some adjustments to how types are defined. You can also use the Compatibility to add a "Web Reference" instead (which is based on ASP 2.0 or "classic" web services).
This sounds like an issue with the design of the webservice that you are calling. You'll likely have to tweak your reference to match the service.
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
Saturday, April 11, 2015 5:14 PM
Yes, I do send credentials. They are using an https site.
I do an initialize at start up. Then call the SOAP call. And I added at the top where I create what ceritfication to use
Imports System.Security.Cryptography.X509Certificates
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Net
Imports System.Xml
Imports System.IO.Compression
Imports System.ServiceModel
Dim cert As X509Certificate2 = New X509Certificate2(Application.StartupPath & "\MyCert.cer", "MyPassowrd")
Public Function wbs_Initialze() As Boolean
Dim boolReturn As Boolean = False
Try
MyService.PreAuthenticate = True
MyService.Url = "https://CustomerSite"
Dim intThis As Integer = MyService.ClientCertificates.Add(cert)
MyService.Timeout = 60000
boolReturn = True
Catch ew As SoapException
MessageBox.Show(ew.Message)
Catch ex As Exception
comVariabes.strTestTheory = ex.Message
boolReturn = False
End Try
Return boolReturn
End Function
Public Function wbs_GetEmailFromUsername(strUserName As String) As String
Dim strResult As String = ""
Try
strResult = MyService.GetEmailFromUsername(strUserName.Trim)
If strResult Is Nothing Then
strResult = "NOTHING"
End If
Catch e As SoapException
Dim str As String = e.Code.Name
Console.WriteLine("SOAP Exception Error Code: {0}", str)
Console.WriteLine("SOAP Exception Message is: {0}", e.Message)
End Try
Return strResult
Here is some WSDL code. I had to change out exact names for security reasons.
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:si="http://soapinterop.org/xsd" xmlns:tns="MyData/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="MyData/">
<wsdl:types>
<xsd:schema targetNamespace="MyData/">
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/"/>
<xsd:simpleType name="Username_Type">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[a-zA-Z0-9][\p{P}]{0,25}"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
</wsdl:types>
<message name="GetEmailFromUsernameRequest">
<part name="Username" type="tns:Username_Type"/>
</message>
<message name="GetEmailFromUsernameResponse">
<part name="return" type="xsd:string"/>
</message>
<operation name="GetEmailFromUsername">
<documentation>Retrieves email address from username</documentation>
<input message="tns:GetEmailFromUsernameRequest"/>
<output message="tns:GetEmailFromUsernameResponse"/>
</operation>
</portType>
<binding name="MyBinding" type="tns:MyPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetEmailFromUsername">
<soap:operation soapAction="GetEmailFromUsername" style="rpc"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://MyData"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://MyData"/>
</output>
</operation>
</binding>
<service name="MyService">
<port name="MyPort" binding="tns:MyBinding">
<soap:address location="https://MyData/Mydata"/>
</port>
</service>
</definitions>
Thank You
Saturday, April 11, 2015 5:27 PM
I created by going to Add Service Reference --> Advanced --> Add Web Reference. They sent me the WSDL file and in the URL text box, I pointed it to the path where I put the WSDL file.
Saturday, April 11, 2015 8:08 PM
Have you tried adding the reference without using Advanced?
I typically do not ever need to use the Advanced -> Add Web Reference, even with working with classic ASP Web Services. So you might try a fresh project where you add the reference using the Service Reference dialog.
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
Sunday, April 12, 2015 3:39 PM
Thanks Reed, I will check that out. I am new to web services and I just went with what I found in searching for SOAP calls.
Friday, April 17, 2015 10:35 PM
I have more information that may help the situation. I worked with the IT person who set up the WSDL. She monitored what I was doing.
I changed the soap:body use="encoded" to soap:body use="literal".
She sees my request, the database does it's thing and gets the email address and she sees her end send out that email address. When I recieve the information, the string passed back to me is "NOTHING".
Now here is the other part. So if I send a request without a parameter, and I have it set as "encoded", I see the string information back. I switch it to "literal" and I get "NOTHING" back.
as in - "If strMyString is NOTHING Then"
Hope this helps and Thanks,
Brian