none
Consuming WCF service in JAVA RRS feed

  • Question

  • Hello ,

    We are consuming OMCF web service using JAVA - JAXWS web client.  OMCF is configured for transport security with basic authetication. I am passing the required certificate and username/password. But I get unauthroized as a response.

    Is it possible to consume WCF web service / OMCF web service  in java?

    If anybody of you have done this before please let me know and I will provide the config file and also the java code that I am using to connect to the service.

    Thanks and Regards,

    Swati

    Wednesday, August 10, 2016 4:56 PM

Answers

  • Hello,

    To enable wcf tracing you also need to add the following inside <system.serviceModel>

      <diagnostics wmiProviderEnabled="true">
          <messageLogging 
               logEntireMessage="true" 
               logMalformedMessages="true"
               logMessagesAtServiceLevel="true" 
               logMessagesAtTransportLevel="true"
               maxMessagesToLog="3000" 
           />
      </diagnostics>

    Based on your response, I believe you are not able to consume the service from java or c#.  My suggestion would be to get the c# to work and use the tracing to get the java to work (a tool like soapui might prove useful).

    Based on the service config this looks like a more complex binding (client certificate) so I suggest trying to get an example OMCF project working first.


    Jeff

    • Marked as answer by KadamSwati Friday, September 9, 2016 11:43 PM
    Wednesday, August 31, 2016 11:45 PM

All replies

  • Hello Swati,

    The best way to determine the differences between the java request and a WCF client is to use WCF tracing.  First step is to get tracing on and then compare the message exchange to spot the difference.

    Good luck!


    Jeff

    Wednesday, August 10, 2016 8:31 PM
  • Hello Jeff,

    I have enabled trace in the web service config file. I am attaching the file here. Please let me know this is enough or I have to enable trace somewhere else also.

    However I don't see any trace logs displayed in the log file after I send SOAP request from my JAVA client. Please check below config file <system.diagnostics> section. Is this enough or I need to add anything more to enable trace? 

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
     <configSections>
        <section name="uri" type="System.Configuration.UriSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </configSections>
    <system.diagnostics>
      <sources> 
       <source name="System.ServiceModel" switchValue="Information, ActivityTracing" 
        propagateActivity="true"> 
        <listeners> 
         <add type="System.Diagnostics.DefaultTraceListener" name="Default"> 
          <filter type="" /> 
         </add> 
         <add name="McfTracing"> 
          <filter type="" /> 
         </add> 
        </listeners> 
       </source> 
       <source name="System.ServiceModel.MessageLogging" switchValue="Information, ActivityTracing"> 
        <listeners> 
         <add type="System.Diagnostics.DefaultTraceListener" name="Default"> 
          <filter type="" /> 
         </add> 
         <add name="McfTracing"> 
          <filter type="" /> 
         </add> 
        </listeners> 
       </source> 
      </sources> 
      <sharedListeners> 
     <add initializeData="c:\Microsoft.Mom.Sdk.ServiceHost_tracelog" 
        type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
        name="McfTracing" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack"> 
        <filter type="" /> 
       </add> 
      </sharedListeners> 
    </system.diagnostics> 
     
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
      </startup>
      <uri>
        <iriParsing enabled="true" />
      </uri>
        <runtime>
          <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
              <assemblyIdentity name="Microsoft.EnterpriseManagement.HealthService" publicKeyToken="31bf3856ad364e35" />
              <publisherPolicy apply="no" />
              <bindingRedirect oldVersion="6.0.4900.0" newVersion="7.0.5000.0" />
            </dependentAssembly>
            <publisherPolicy apply="no" />
            <probing privatePath="" />
          </assemblyBinding>
          <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
              <assemblyIdentity name="Microsoft.Mom.Common" publicKeyToken="31bf3856ad364e35" />
              <publisherPolicy apply="no" />
              <bindingRedirect oldVersion="6.0.4900.0" newVersion="7.0.5000.0" />
            </dependentAssembly>
            <publisherPolicy apply="no" />
            <probing privatePath="" />
          </assemblyBinding>
          <gcConcurrent enabled="false"/>
          <gcServer enabled="true"/> 
        </runtime> 
        <appSettings>
    <!-- use appSetting to configure base address provided by host -->
    <add key="baseAddressMcfV3" value="https://10.50.11.111:51905/ConnectorFramework" />
        </appSettings>

        <system.serviceModel>

    <bindings> 
          <wsHttpBinding> 
              <binding name="McfDefaultBinding" 
    maxReceivedMessageSize="2147483647"> 
                  <readerQuotas maxDepth="2147483647" 
    maxStringContentLength="2147483647" 
                      maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
    maxNameTableCharCount="2147483647" /> 
                  <security mode="Transport"> 

                      <transport clientCredentialType="Basic" />
           
                  </security> 
              </binding> 
          </wsHttpBinding> 
      </bindings> 

            <behaviors>
                <serviceBehaviors>
                    <behavior name="ConnectorFrameworkServiceBehavior">
                        <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
                        <serviceMetadata  httpsGetEnabled="true"  httpsGetUrl="https://10.50.11.111:51905/ConnectorFramework" 
                           />
                        <serviceThrottling maxConcurrentSessions="1000" />
                        <serviceCredentials> 
                            <clientCertificate> 
                                <authentication mapClientCertificateToWindowsAccount="true" /> 
                            </clientCertificate> 
                        </serviceCredentials> 
                    </behavior>
                </serviceBehaviors>
            </behaviors>

            <services>
            <service behaviorConfiguration="ConnectorFrameworkServiceBehavior"
                    name="Microsoft.EnterpriseManagement.ConnectorFramework.ServiceDataLayer.ConnectorFrameworkDataAccess">
                    <endpoint address="mex" binding="mexHttpsBinding" name="WsdlPublishing"
                        contract="IMetadataExchange" />
                    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="McfDefaultBinding"
                        name="Main" contract="Microsoft.EnterpriseManagement.ConnectorFramework.IConnectorFramework" />
                </service>



            </services>

        </system.serviceModel> 
     
    </configuration>

    Wednesday, August 10, 2016 11:56 PM
  • Great.  If I understand correctly, you see a trace when a WCF client calls the service but not a JAVA client.  If this is the case then I suspect the JAVA client is not even making it to the WCF service so do you have a trace on the JAVA side and or a error message?

    Are you hosting the service in IIS?  The reason why I ask is usually IIS does not enforce security so I would expect some error in the WCF service trace file for failed authentication attempts.


    Jeff

    Thursday, August 11, 2016 12:03 AM
  • JAVA  client is making it to the srevice. Because below is the response I receive.

    Yes. This service is hosted in IIS.

    I am receiving SOAP response as:

    ---[HTTP response - https://10.50.1.153:51905/ConnectorFramework - 401]---
    null: [HTTP/1.1 401 Unauthorized]
    Content-Length: [0]
    Date: [Thu, 11 Aug 2016 22:53:26 GMT]
    Server: [Microsoft-HTTPAPI/2.0]
    WWW-Authenticate: [Basic realm=""]
    --------------------

    And below is the exception I get upon soap call:

    Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 401: Unauthorized
        at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.checkStatusCode(HttpTransportPipe.java:296)
        at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:245)
        at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:203)
        at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:122)
        at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:123)
        at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:626)
        at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:585)
        at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:570)
        at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:467)
        at com.sun.xml.internal.ws.client.Stub.process(Stub.java:308)
        at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:163)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
        at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
        at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:135)
        at com.sun.proxy.$Proxy30.setupWithConnectorId(Unknown Source)
        at Omcf.connector.main(connector.java:291)

    Below is My java code:

    QName qname = new QName("http://tempuri.org/","ConnectorFrameworkDataAccess");
                ObjectFactory factory = new ObjectFactory();
            
                JAXBElement<String> connName = new JAXBElement<String>(qname, String.class,"ConnectorFrameworkDataAccess");
                
                JAXBElement<String> displayName = new JAXBElement<String>(qname, String.class,"ConnectorFrameworkDataAccess");
                JAXBElement<String> description = new JAXBElement<String>(qname, String.class,"ConnectorFrameworkDataAccess");

    ConnectorFrameworkDataAccess omcfService = new ConnectorFrameworkDataAccess();//(url);
                
                IConnectorFramework omcfPort = omcfService.getPort(IConnectorFramework.class);
                
                BindingProvider omcfBinding = ((BindingProvider)omcfPort);
                
                List<javax.xml.ws.handler.Handler> handlers = omcfBinding.getBinding().getHandlerChain();
                handlers.add(new MyServiceLogHandler());
                omcfBinding.getBinding().setHandlerChain(handlers);
        
                omcfBinding.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,"https://10.50.11.111:11115/ConnectorFramework?wsdl=wsdl0" );
                omcfBinding.getRequestContext().put(BindingProvider.USERNAME_PROPERTY,("DOMAIN_NAME\\USERNAME".getBytes()));
                omcfBinding.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,"PASSWORD".getBytes());
                       //providing user/password in the SOAP header
                  Map<String, Object> req_ctx = ((BindingProvider)omcfPort).getRequestContext();       

        //Defining obj of interface(ServiceContract)
                IConnectorFramework connFramework = omcfService.getMain();

    //soap request

    connFramework.setupWithConnectorId(connInfo, "xsdsdssdsd");


    • Edited by KadamSwati Thursday, August 11, 2016 11:08 PM
    Thursday, August 11, 2016 11:00 PM
  • Hello KadamSwati,

    I am not sure... You should be getting some indication in the wcf service trace so my guess is the request is getting blocked before it gets handed off to the worker process.

    Just to confirm:  You have a wcf client that works and java client that not (unauthorized).  You can see the trace of the wcf client activity in the server trace file.

    Is this a permissions issue then?  Here are some links that might give you a pointer in the right direction.

    http://www.yzjingying.net/614251291.htm

    http://coderanch.com/t/625532/Web-Services/java/create-webservice-client-WSDL

    https://scn.sap.com/thread/1791898

    http://stackoverflow.com/questions/36585794/clienttransportexception-the-server-sent-http-status-code-302-found

    http://stackoverflow.com/questions/4865165/jax-ws-sharepoint-401-unauthorized-ntlm

    Sorry I could not be more help!

     

    Jeff

    Thursday, August 11, 2016 11:23 PM
  • Hello Jeff,

    Here is the statck trace I received when I send a request through the C# client

    /StackTrace><ExceptionString>System.ServiceModel.Security.MessageSecurityException: The HTTP request was forbidden with client authentication scheme 'Basic'. ---&amp;gt; System.Net.WebException: The remote server returned an error: (403) Forbidden.
       at System.Net.HttpWebRequest.GetResponse()
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       --- End of inner exception stack trace ---</ExceptionString><InnerException><ExceptionType>System.Net.WebException, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>The remote server returned an error: (403) Forbidden.</Message><StackTrace>   at System.Net.HttpWebRequest.GetResponse()
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)</StackTrace><ExceptionString>System.Net.WebException: The remote server returned an error: (403) Forbidden.
       at System.Net.HttpWebRequest.GetResponse()
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)</ExceptionString></InnerException></Exception></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131075</EventID><Type>3</Type><SubType Name="Error">0</SubType><Level>2</Level><TimeCreated SystemTime="2016-08-31T22:52:22.8345738Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{c1d98230-2455-46e9-b431-b10bde5b4191}" /><Execution ProcessName="OMCFApp.vshost" ProcessID="23140" ThreadID="7" /><Channel/><Computer>SKADAM</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error"><TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier><Description>Throwing an exception.</Description><AppDomain>OMCFApp.vshost.exe</AppDomain><Exception><ExceptionType>System.ServiceModel.Security.MessageSecurityException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>The HTTP request was forbidden with client authentication scheme 'Basic'.</Message><StackTrace>   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest request, HttpWebResponse response, WebException responseException, HttpChannelFactory`1 factory)
       at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)

    Do you have any idea what might be the issue?

    Wednesday, August 31, 2016 11:23 PM
  • Hello,

    To enable wcf tracing you also need to add the following inside <system.serviceModel>

      <diagnostics wmiProviderEnabled="true">
          <messageLogging 
               logEntireMessage="true" 
               logMalformedMessages="true"
               logMessagesAtServiceLevel="true" 
               logMessagesAtTransportLevel="true"
               maxMessagesToLog="3000" 
           />
      </diagnostics>

    Based on your response, I believe you are not able to consume the service from java or c#.  My suggestion would be to get the c# to work and use the tracing to get the java to work (a tool like soapui might prove useful).

    Based on the service config this looks like a more complex binding (client certificate) so I suggest trying to get an example OMCF project working first.


    Jeff

    • Marked as answer by KadamSwati Friday, September 9, 2016 11:43 PM
    Wednesday, August 31, 2016 11:45 PM
  • Hello Jeff,

    Thanks for your response. I am able to autheticate OMCF web service through the JAVA. I could see the log trace and that helped me to see the error messages. Thaks again for your time.

    Thanks and Regards,

    Swati Kadam

    Friday, September 9, 2016 11:43 PM
  • Can you pls let me know how it started work?
    Thursday, May 10, 2018 11:17 AM