3

我通过右键单击并添加服务引用将 java Web 服务消耗到我的 asp.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 :{"Fault occurred while processing."} 服务器堆栈跟踪:在 System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action,布尔单程,ProxyOperationRuntime 操作,Object[] 输入,Object[] 输出,TimeSpan 超时)在 System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔单程,ProxyOperationRuntime 操作,Object[] 输入,Object[] 输出)在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

在 [0] 处重新抛出异常:在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 处的 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 处。 getCities(getCities 请求)在 c:\Windows\Microsoft.NET\Framework\Temporary ASP.NET Files\website1\bdbbd757\4abd3cb7\App_WebReferences.mggi9qhe 中的 salim.HakedisServiceClient.salim.HakedisService.getCities(getCities 请求) .0.cs:第 1392 行,位于 c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website1\bdbbd757\4abd3cb7\App_WebReferences.mggi9qhe.0.cs 中的 salim.HakedisServiceClient.getCities() :c:\Users\htsapp\Documents\Visual Studio 2008\WebSites\WebSite1\Default.aspx.cs 中 _Default.Page_Load(Object sender, EventArgs e) 的第 1398 行:System.Web 的第 80 行。Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at System.Web.UI.Control.LoadRecursive() 在 System.Web.UI.Page.ProcessRequestMain(布尔 includeStagesBeforeAsyncPoint,布尔 includeStagesAfterAsyncPoint)

和这样的网络服务:

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

有人有建议吗?

4

1 回答 1

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.

希望它有所帮助(您可以首先调试)。

于 2012-07-27T12:12:21.067 回答