开发者

Basic post to test web service

I am working on form, which send input to webservice via post and display result. It must be simple, and it works fine on localhost. But when I try to use it agains live I have error 500.

Here is my code:

 WebRequest request = WebRequest.Create("http://localhost:3192/WebServices/Export.asmx/" + uxAction.SelectedValue);
                UTF8Encoding encoding = new UTF8Encoding();
                byte[] data = encoding.GetBytes(uxRequest.Text);
                request.Method = "POST";
                request.ContentType = "text/xml; charset=utf-8";
                request.ContentLength = data.Length;

                Stream requestStream = request.GetRequestStream();
                requestStream.Write(data, 0, data.Length);
                requestStream.Flush();
                requestStream.Close();

                WebResponse response = request.GetResponse();
                Stream newStream = response.GetResponseStream();
                byte[] responseArray = new byte[response.ContentLength];
                newStream.Read(responseArray, 0, (int)response.ContentLength);
                newStream.Close();

                uxResponse.Text = encoding.GetString(responseArray);

And here is information about error

 Exception information: 
        Exception type: InvalidOperationException 
        Exception message: Request format is unrecognized for URL unexpectedly ending in '/GetProjectTypes'. 

    Request information: 
        Request URL: http://sitename.com/WebServices/Export.asmx/GetProjectTypes 
        Request path: /WebServices/Export.asmx/GetProjectTypes 
        User host address: 93.73.249.242 
        User:  
        Is authenticated: False 
        Authentication Type:  
        Thread account name: NT AUTHORITY\NETWORK SERVICE 


Thread information: 
    Thread ID: 1 
    Thread account name: NT AUTHORITY\NETWORK SERVICE 
    Is impersonating: False 
    Stack trace:    at System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
   at System.开发者_开发技巧Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
   at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
   at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
   at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I also have http handler to access web services from javascript and this works fine:

<add verb="GET,HEAD,POST*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

Here is my request data. Exception is same with or without it. Webservice do not have any parameters

<?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>
    <GetProjectTypes xmlns="http://sitename.com/WebServices/Export.asmx" />
  </soap:Body>
</soap:Envelope>


When we test webservice in browser, it adds methodname to url, but when we do post this is not needed. I removed '/" + uxAction.SelectedValue' and everything is working fine now

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜