2010-01-11 109 views
0

我正在處理表單,它通過發佈和顯示結果向web服務發送輸入。它一定很簡單,並且它在localhost上工作正常。但是,當我嘗試使用它agains直播我有錯誤500測試Web服務的基本職位

這裏是我的代碼:

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); 

,這裏是有關錯誤信息

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) 

我也有HTTP處理程序訪問從javascript的網絡服務和這工作正常:

<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"/> 

這是我的請求數據。例外情況相同或不相同。 web服務沒有任何參數

<?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> 
+0

你正確編碼的POST數據('HttpUtility.UrlEncode()'等等)? – 2010-01-11 18:41:06

+0

我應該這樣做對XML數據? 內XML的一切都非常簡單 – st78 2010-01-11 18:49:06

+0

請顯示如何填充'數據'變量 – 2010-01-11 18:51:25

回答

0

當我們測試的瀏覽器的web服務,把它添加到methodName中的URL,但是當我們發佈,這是沒有必要的。 我刪除了「/」 + uxAction.SelectedValue」和一切工作現在罰款