2012-07-25 172 views
3

我已通過右鍵單擊並添加服務引用來使用java web服務到我的asp.net項目。Java Web服務消費.Net

public static salim.HakedisServiceClient ws = new salim.HakedisServiceClient("HakedisServiceImplPort"); ws.ClientCredentials.UserName.UserName = "****"; ws.ClientCredentials.UserName.Password = "****"; var lstCities = ws.getCities();

但它也有一個這樣的例外:

System.ServiceModel.FaultException:{ 「故障發生時的處理。」} 服務器堆棧跟蹤: 在System.ServiceModel.Channels。 ServiceChannel.HandleReply(ProxyOperationRuntime操作,ProxyRpc & rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan timeout) at System.ServiceModel .Cha在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作) 在System.ServiceModel.Channels上運行nnels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs) .ServiceChannelProxy.Invoke(即時聊天消息)在

異常重新拋出[0]: 在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即時聊天reqMsg,即時聊天retMsg) 在System.Runtime.Remoting.Proxies.RealProxy .PrivateInvoke(MessageData & msgData,Int32類型) at salim.HakedisService.getCities(getCities request) at salim.HakedisServiceClient.salim.HakedisService.getCi (c:\ Windows \ Microsoft.NET \ Framework \ v2.0.50727 \ Temporary ASP.NET Files \ website1 \ bdbbd757 \ 4abd3cb7 \ App_WebReferences.mggi9qhe.0.cs:line 1392 at salim.HakedisServiceClient.getCities中的關係(getCities請求) ()in c:\ Windows \ Microsoft.NET \ Framework \ v2.0.50727 \ Temporary ASP.NET Files \ website1 \ bdbbd757 \ 4abd3cb7 \ App_WebReferences.mggi9qhe.0.cs:line 1398 at _Default.Page_Load(Object sender,EventArgs e)在c:\ Users \ htsapp \ Documents \ Visual Studio 2008 \ WebSites \ WebSite1 \ Default.aspx.cs:line 80 at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,Object o,Object t,EventArgs E) 在System.Web.Util.CalliEventHandlerDelegateProxy.Callback(對象發件人,EventArgs的) 在System.Web.UI.Control.OnLoad(EventArgs的) 在System.Web.UI.Control.LoadRecursive() 在System.Web.U I.Page.ProcessRequestMain(布爾includeStagesBeforeAsyncPoint,布爾includeStagesAfterAsyncPoint)

和WebService這樣:

<wsdl:definitions name="Hakedis" targetNamespace="http://hakedis.eventhandler.archibus.com/"> 
<wsdl:types></wsdl:types> 
<wsdl:message name="getFloors"></wsdl:message> 
<wsdl:message name="getRooms"></wsdl:message> 
<wsdl:message name="getBuildingPropertiesResponse"></wsdl:message> 
<wsdl:message name="getBuildingProperties"></wsdl:message> 
<wsdl:message name="getBuildingTypes"></wsdl:message> 
<wsdl:message name="getBuildingTypesResponse"></wsdl:message> 
<wsdl:message name="getFloorsResponse"></wsdl:message> 
<wsdl:message name="getRoomsResponse"></wsdl:message> 
<wsdl:message name="getCities"></wsdl:message> 
<wsdl:message name="getCitiesResponse"></wsdl:message> 
<wsdl:message name="getBuildingsResponse"></wsdl:message> 
<wsdl:message name="getBuildings"></wsdl:message> 
<wsdl:portType name="HakedisService"></wsdl:portType> 
<wsdl:binding name="HakedisSoapBinding" type="tns:HakedisService"></wsdl:binding>  <wsdl:service name="Hakedis"></wsdl:service></wsdl:definitions> 

人有建議?

+0

嘗試使用類似['Fiddler'](http://www.fiddler2.com/)的工具來查看哪些數據真的來回流動。您也可能會在.NET沒有采用的底層響應中獲得更好的錯誤消息。 – mellamokb 2012-07-25 17:04:24

+1

你可以添加StackTrace的內容嗎? – 2012-07-25 17:08:13

+0

我無法讀取圖像中的文字。但是它根本不像Java。 – 2012-07-25 17:09:33

回答

2

嘗試設置您的連接,如下所示:

HakedisServiceClient client = null; 
      ChannelEndpointElement endpoint = null; 

      ClientSection clientSection = ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;    
      ChannelEndpointElementCollection endpointCollection = clientSection.ElementInformation.Properties[string.Empty].Value as ChannelEndpointElementCollection; 
      foreach (ChannelEndpointElement endpointElement in endpointCollection) 
      { 
       if (endpointElement.Name == "BasicHttpBinding_HakedisService") //BasicHttpBinding_HakedisService from your config file client endpoint entries 
       { 
        endpoint = endpointElement; 
       } 
      } 

      if (endpoint != null) 
      { 

       BasicHttpBinding binding = new BasicHttpBinding(endpoint.Name); 

       binding.SendTimeout = TimeSpan.FromMinutes(1); //Set all this as appropriate 
       binding.OpenTimeout = TimeSpan.FromMinutes(1); 
       binding.CloseTimeout = TimeSpan.FromMinutes(1); 
       binding.ReceiveTimeout = TimeSpan.FromMinutes(10); 
       binding.AllowCookies = false; 
       binding.BypassProxyOnLocal = false; 
       binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; 
       binding.MessageEncoding = WSMessageEncoding.Text; 
       binding.TextEncoding = System.Text.Encoding.UTF8; 
       binding.TransferMode = TransferMode.Buffered; 
       binding.UseDefaultWebProxy = true; 
       binding.MaxBufferSize = 100000; //as large as needed 
       binding.MaxReceivedMessageSize = 100000; //as large as needed 
       binding.TextEncoding = Encoding.UTF8; 


       System.ServiceModel.EndpointAddress address = new System.ServiceModel.EndpointAddress(endpoint.Address.AbsoluteUri); 
       SSLAccessPolicy.AllowSSLConnection(); 
       client = new HakedisServiceClient(binding, address); 

       SSLAccessPolicy.AllowSSLConnection(); // only if ssl enabled 
       client.Open(); // Now open the client socket. 

希望它可以幫助(你可以通過在第一次調試)。