I am trying to make a Xamarin forms project that gets data from an ASMX Webservice
This is the code I am using
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("SOAPAction", "http://mobile.xn--schller-golf-xjb.dk/WebServices/IndoorServices.asmx/IndoorBruttoGns");
string soapstr = string.Format(#"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
<soap:Body>
< IndoorBruttoGns xmlns = ""http://mobile.xn--schller-golf-xjb.dk/WebServices"" />
</soap:Body>
</soap:Envelope>");
var response = httpClient.PostAsync("http://mobile.xn--schller-golf-xjb.dk/WebServices/IndoorServices.asmx/IndoorBruttoGns", new StringContent(soapstr, Encoding.UTF8, "application/json")).Result;
var content = response.Content.ReadAsStringAsync().Result;
return content;
The Webservice doesn't need any input but I get a 500 internal server error and I know the Webservice works because I call it from a PhoneGap project using $.ajax
Related
I am having trouble debugging a classic asp file in which I call a .NET web service. I am hoping that I can use Fiddler to see why the HTTP request to the web service is returning a 'Bad Request' error. I have a console application to request the classic asp file. Within the classic asp file I call the web service. When I run Fiddler, I see the request to the asp file but not the request to the web service. There is just one line in Fiddler with the asp file request.
Any suggestions or advice to troubleshoot the asp file would be appreciated.
Below is the code to sends a GET request to the web service.
The response in the console application is:
Status: 200
Status text: OK
But the call to the web service does not appear in Fiddler, only the call to the asp file. The web service and asp file are on different servers.
Shouldn't I see this call to the web service on Fiddler?
I want to debug a POST request but first I must learn how to use Fiddler. :)
This is my console application that calls the asp page:
Uri aspPServiceUri = new Uri("http://<serverNameAndPath>/FirstPage.asp?<parameters>;");
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(aspPServiceUri);
httpWebRequest.Method = "GET";
HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse();
Stream resStream = resp.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
string strResponse = reader.ReadToEnd();
Console.WriteLine(strResponse);
reader.Close();
This the asp file:
Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
URL = "http://<serverName>:<port>/PService/PService.Paging.svc?WSDL"
httpRequest.Open "GET", URL, False
httpRequest.Send()
Dim strResult
Dim strStatusText
Response.ContentType = "text/xml"
strStatusText = "Status: " & httpRequest.status & vbCrLf & "Status text: " & httpRequest.statusText
Response.Write(vbCrLf & strStatusText & vbCrLf)
Assuming you are using IIS 7+ or a relatively recent version of IIS Express, add the following to your web.config file. If you don't already have a web.config, then add one.
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy autoDetect="False" bypassonlocal="False" proxyaddress="http://127.0.0.1:8888" usesystemdefault="False" />
</defaultProxy>
</system.net>
This configures Fiddler as a proxy, so all HTTP requests from the web app will be routed through Fiddler.
I am trying to call my .NET web service from a classic asp file. I have to update the asp file to connect to a new web service. This asp file is called by a 3rd party application and it pages a user. I created a .NET console application to test this .asp file to simulate the 3rd party application's use of it. The console application runs locally.
When I run the console application, that runs the new version of the asp file that connects to my web service, there are no errors until I try to display the return result from the web service. I suspect my SOAP request is incorrect.
The web service method is called 'TestMethod' and has no parameters.
This is the URL of the web service: 'http://:/Service1/Service1.Paging.svc'
This is my asp code:
Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
URL = "http://<servername><port>/Service1/Service1.Paging.svc/"
httpRequest.Open "POST", URL, False
httpRequest.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
httpRequest.setRequestHeader "SOAPAction", URL & "TestMethod"
Dim strSoapReq
strSoapReq = "<?xml version=""1.0"" encoding=""utf-8"" ?>"
strSoapReq = strSoapReq & "<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">"
strSoapReq = strSoapReq & "<s:Body>"
strSoapReq = strSoapReq & "<TestMethod xmlns=""http://<servername><port>/Service1"">"
strSoapReq = strSoapReq & "</TestMethod>"
strSoapReq = strSoapReq & "</s:Body>"
strSoapReq = strSoapReq & "</s:Envelope>"
Response.Write(strSoapReq)
httpRequest.Send(strSoapReq)
Dim strResult
strResult = httpRequest.responseText
If IsNull(strResult) Then
strResult = "No result"
End If
Response.Write("Result from web service: " & strResult);
If I comment out the Response.Write there is no error. The console application completes. If I attempt to write the result, I get a 500 error.
I cannot debug the asp. It is on a production server and there are no Visual Studio IDEs on the server.
Is my SOAP request correct? (strSoapReq)
I am not sure that I am defining the namespace correctly. Should it just be the path with the namespace at the end?
If anyone has any ideas on how to debug this file, I would appreciate it.
Lastly, all the TestMethod() does is return a string, "Connected to TestMethod"
UPDATE
I can connect to my web service. When I run my console application, it returns the standard message of a web service when you but the URL in the web browser. Basically..."
The TestMethod() is not called in the .asp file
When requesting the SOAPAction, is this line correct?
URL = "http://<serverName>:<port>/Service1/Service1.Paging.svc"
httpRequest.setRequestHeader "SOAPAction", URL & "/TestMethod"
Secondly, I suspect my SOAP request string might not be correct.
In defining the namespace, I am doing the following:
'":/Service1"">"'
I have a classic asp file that needs to connect to a web service.
I am confused as to how to define the URL for the web service and the Namespace in the SOAPAction.
When I run my code and write a Response.Write for the return value of the method that I am calling in the web service, it either returns the wsdl or the web page for the service
This code displays the web service html as if you are entering the web service .svc url:
Dim strSoapReq
strSoapReq = "<?xml version=""1.0"" encoding=""utf-8"" ?>"
strSoapReq = strSoapReq & "<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">"
strSoapReq = strSoapReq & "<s:Body>"
strSoapReq = strSoapReq & "<TestMethod xmlns=""http:<serverName:<port>/PagingService/PagingService"">"
strSoapReq = strSoapReq & "</TestMethod>"
strSoapReq = strSoapReq & "</s:Body>"
strSoapReq = strSoapReq & "</s:Envelope>"
'Create server-side component to make requests
Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
URL = "http:<serverName:<port>/PagingService/PagingService.Paging.svc"
httpRequest.Open "GET", URL, False
httpRequest.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
httpRequest.setRequestHeader "SOAPAction", URL & "/TestMethod"
httpRequest.Send(strSoapReq)
Dim strResult
strResult = httpRequest.responseText
Response.Write(vbCrLf & "Result from web service call: " & vbCrLf & strResult)
If I add the ?wsdl to the end of the service url, it shows the WSDL.
How can I call the method in the web service?
UPDATE
I changed my code to the following:
Dim NS, NS_SOAP, NS_SOAPENC, NS_XSI, NS_XSD
NS = "http://<server>/PagingService/"
NS_SOAP = "http://schemas.xmlsoap.org/soap/envelope/"
NS_SOAPENC = "http://schemas.xmlsoap.org/soap/encoding"
NS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
NS_XSD = "http://www.w3.org/2001/XMLSchema"
Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
URL = "http://<server>/PagingService/PagingService.Paging.svc?WSDL"
httpRequest.Open "POST", URL, False
httpRequest.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
httpRequest.setRequestHeader "SOAPAction", "http://<server>/PagingService/TestMethod"
' XML DOM objects.
Dim DOM, Envelope, Body, Operation, Param
' Creates an XML DOM object.
Set DOM = CreateObject("MSXML2.DOMDocument.6.0")
' Creates the main elements.
Set Envelope = DOM.createNode(1, "soap:Envelope", NS_SOAP)
Envelope.setAttribute "xmlns:soapenc", NS_SOAPENC
Envelope.setAttribute "xmlns:xsi", NS_XSI
Envelope.setAttribute "xmlns:xsd", NS_XSD
DOM.appendChild Envelope
Set Body = DOM.createElement("soap:Body")
Envelope.appendChild Body
' Creates an element for the TestMethod function.
Set Operation = DOM.createNode(1, "TestMethod", NS)
Body.appendChild Operation
' Releases the objects.
Set Operation = Nothing
Set Body = Nothing
Set Envelope = Nothing
httpRequest.Send(DOM.xml)
Dim strResult
strResult = httpRequest.status
Response.Write(vbCrLf & "Result from web service call: " & vbCrLf & strResult)
The http.Status result with this code is: 415 - unsupported media
I saw a post with this error and they corrected it by changing the Content-Type. When I tried this:
httpRequest.setRequestHeader "Content-Type", "application/soap+xml; charset=utf-8"
I got the status value of 400 - Bad request.
Finally figured this one out. Below is my code in case some poor minion needs to do this...maybe it will lessen the pain and shorten the time to get it to run.
I connected a WCF web service (file extension, .svc) to a classic .asp file.
I had to add a basicHttpBinding to the web service. It can also be secure (HTTPS).
This is the binding added to the service config. file:
(Note the name of it. defined by address attribute.
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPaging" contract="PagingService.IPaging">
</endpoint>
Added this to the bindings part of the config file:
<basicHttpBinding>
<binding name="BasicHttpBinding_IPaging"></binding>
</basicHttpBinding>
You need to recompile the project so the WSDL has this binding in its definition.
Now the fun part....classic asp :( written in VBScript.
The SOAP envelope gave me the most trouble:
'Namespaces
Dim NS, NS_SOAP, NS_SOAPENC, NS_XSI, NS_XSD, NS_SOAP_ACTION
'NS is the name of YOUR namespace. If you did not define it
'in the service interface it is probably the same as this
NS = "http://tempuri.org/"
'It is for SOAP 1.1 - my version of .asp could only use SOAP 1.1
NS_SOAP = "http://schemas.xmlsoap.org/soap/envelope/"
'Next 3 definitions are standard - just copy
NS_SOAPENC = "http://schemas.xmlsoap.org/soap/encoding"
NS_XSI = "http://www.w3.org/2001/XMLSchema-instance"
NS_XSD = "http://www.w3.org/2001/XMLSchema"
'This should also be in your WSDL. Look up the method you
'want to call; there was an attribute in mine that read 'soap_action'
NS_SOAP_ACTION = "http://tempuri.org/IFileName/<YourMethodName>"
'URL to the WCF service Using basicHttpBinding identified to the name
'you defined in the config file in 'address' attribute
URL = "https://<serverName>:<port>/ServiceFolder/Service.Paging.svc/basic"
'This was the hard part for me. Defining the damn soap message
'XML DOM objects.
Dim Envelope, Body, Operation
Dim ParamUserID, ParamUserName,
'Creates an XML DOM object.
Set objXmlDoc = CreateObject("MSXML2.DOMDocument.6.0")
objXmlDoc.async = false
'Creates the main elements.
Set Envelope = objXmlDoc.createNode(1, "soap:Envelope", NS_SOAP)
Envelope.setAttribute "xmlns:soapenc", NS_SOAPENC
Envelope.setAttribute "xmlns:xsi", NS_XSI
Envelope.setAttribute "xmlns:xsd", NS_XSD
objXmlDoc.appendChild Envelope
Set Body = objXmlDoc.createNode(1, "Body", NS_SOAP)
Envelope.appendChild Body
'Creates an element for the SendPageForGalvanonSystem function.
Set Operation = objXmlDoc.createNode(1, "<MethodName>", NS)
Body.appendChild Operation
'Add all the parameters to the DOM
Set ParamUserID = objXmlDoc.createNode(1, "strUserID", NS)
ParamUserID.text = strUserID
Operation.appendChild ParamUserID
Set ParamUserName = objXmlDoc.createNode(1, "strUserName", NS)
ParamUserName.text = strUserName
Operation.appendChild ParamUserName
Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
httpRequest.Open "POST", URL, False
httpRequest.setRequestHeader "Content-Type", "text/xml"
httpRequest.setRequestHeader "SOAPAction", NS_SOAP_ACTION
httpRequest.send objXmlDoc.xml
'Releases the objects.
Set ParamUserID = Nothing
Set ParamUserName = Nothing
Set Operation = Nothing
Set Body = Nothing
Set Envelope = Nothing
Is it possible to call the WSO2 API Manager:: publisher api, as described in:
http://docs.wso2.org/display/AM150/Publisher+APIs
From a webservice, instead fronm JSON
Greetz,
Marc
You can simply call those jaggery endpoints from webservices.
Do a simple HTTP Post to those endpoints;
Eg:
// create a post request to addAPI.
String addAPIendpoint = "http://localhost:9763/publisher/site/blocks/item-add/ajax/add.jag";
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(addAPIendpoint);
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>(12);
params.add(new BasicNameValuePair(API_ACTION, API_ADD_ACTION));
params.add(new BasicNameValuePair(API_NAME, serviceName));
params.add(new BasicNameValuePair(API_CONTEXT, serviceName));
.....
HttpResponse response = httpclient.execute(httppost, httpContext);
I have a web service running on my local apache tomcat. I can successfully talk to it via SoapUI. However, when I write a client in Java, it does not give me a response !
Here is the client code:
SOAPConnectionFactory myFct = SOAPConnectionFactory.newInstance();
SOAPConnection myCon = myFct.createConnection();
MessageFactory myMsgFct = MessageFactory.newInstance();
SOAPMessage message = myMsgFct.createMessage();
SOAPPart mySPart = message.getSOAPPart();
SOAPEnvelope myEnvp = mySPart.getEnvelope();
SOAPBody body = myEnvp.getBody();
Name bodyName = myEnvp.createName("Ping", "ws","http://ws.myeclipseide.com/");
SOAPBodyElement gltp = body.addBodyElement(bodyName);
Name myContent1 = myEnvp.createName("arg0");
SOAPElement mySymbol1 = gltp.addChildElement(myContent1);
mySymbol1.addTextNode("test");
message.saveChanges();
URLEndpoint endPt = new URLEndpoint("http://localhost:8080/PingWebService/StringPingPort?WSDL");
SOAPMessage reply = myCon.call(message, endPt);
myCon.close();
System.out.println("Response: "+reply.getContentDescription());
The call through soapUI looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.myeclipseide.com/">
<soapenv:Header/>
<soapenv:Body>
<ws:Ping>
<!--Optional:-->
<arg0>testing this</arg0>
</ws:Ping>
</soapenv:Body>
</soapenv:Envelope>
Any idea why it would not work through java???
Does not work
Exception, error message, no call,... ?
At first glance, I cannot see anything obvious but since you are using Eclipse, activate the TCP Monitor under Eclipse, issue your call by running you program from Eclipse and check what is sent on the wire.
getContentDescription() "Returns: a String describing the content of this message or null if no description has been set" and NOT the content of your message.
Try this:
ByteArrayOutputStream out = new ByteArrayOutputStream();
reply.writeTo(out);
System.out.println("Response: "+out.toString());