繁体   English   中英

Java Web Service使用.Net

[英]Java Web Service Consume .Net

我通过右键单击并添加服务引用来使用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:{“处理时发生故障。”}服务器堆栈跟踪:System.ServiceModels.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime操作,ProxyRpc和rpc)在System.ServiceModel.Channels.ServiceChannel.Call(String action, System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs)at Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan timeout) System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)中的System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)

在[0]处重新抛出异常:位于salim.HakedisService的System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&msgData,Int32类型)的System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)。 getCities(getCities请求)位于c:\\ Windows \\ Microsoft.NET \\ Framework \\ v2.0.50727 \\ 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() :1398位于_Default.Page_Load(Object sender,EventArgs e)的c:\\ Users \\ htsapp \\ Documents \\ Visual Studio 2008 \\ WebSites \\ WebSite1 \\ Default.aspx.cs:第80行,位于System.Web.Util.CalliHelper.EventArgFunctionCaller System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,EventArgs)中的(IntPtr fp,Object o,Object t,EventArgs e) e)System.Web.UI.Page.ProcessRequestMain上的System.Web.UI.Control.LoadRecursive()中的System.Web.UI.Control.OnLoad(EventArgs e)(布尔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>

有人建议吗?

尝试按如下方式设置连接:

 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.

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM