Java Web Service使用.Net

时间:2012-07-25 16:58:28

标签: c# java asp.net web-services

通过右键单击并添加服务引用,我已将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.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime操作,ProxyRpc& rpc)    在System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs,TimeSpan timeout)    在System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs)    在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)    在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

在[0]处重新抛出异常:    在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)    在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32 type)    在salim.HakedisService.getCities(getCities request)    在salim.HakedisServiceClient.salim.HakedisService.getCities(getCities请求)的c:\ Windows \ Microsoft.NET \ Framework \ v2.0.50727 \ Temporary ASP.NET Files \ website1 \ bdbbd757 \ 4abd3cb7 \ App_WebReferences.mggi9qhe.0.cs: 1392行    在salim.HakedisServiceClient.getCities()在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:第80行    在System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,Object o,Object t,EventArgs e)    在System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,EventArgs e)    在System.Web.UI.Control.OnLoad(EventArgs e)    在System.Web.UI.Control.LoadRecursive()    在System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean 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>

有人建议吗?

1 个答案:

答案 0 :(得分: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.

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