开发者

Error connecting Java App to WCF web service

I've written a simple Java Console Application in Eclipse that references a WCF web service written in C#. Hosting the WCF service locally on my PC, I'm unable to connect to the service using the java client.

The steps I've taken to create the WCF Service are as follows

  1. Create a 'Service1.svc' with the following endpoint:

    string IService1.Hello(string sName) { return "Hello " + sName + "!" ; }

  2. The web config for the service is as follows:

      <system.web>
        <compilation debug="true" targetFramework="4.0" />
      </system.web>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="BasicHttpBinding" />
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding"
            contract="WcfService1.IService1" name="BasicHttpEndpoint" />
        </client>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
     开发者_StackOverflow社区   </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    

  3. I modified the properties so the service will always use port 8888.

  4. I've tested the service using a C# console application.

To Create the Java client, I did the following:

  1. Download and install Glassfish 3.0.1 (Application server) which come bundled with Metro (Web Server)

  2. Use the 'wsimport' tool in the 'bin'directory of my jdk to generate the service reference code for the java client app. The .bat file that I ran to create the service reference

  3. Copy the code from step 2. above into a new Java Application in Eclipse.

  4. Create a new Java class in my console app which calls the web service as follows

`

import java.net.MalformedURLException;

import java.net.URL;

import javax.xml.namespace.QName;

import javax.xml.ws.BindingProvider;

import org.tempuri.Service1;

import org.tempuri.IService1;


public class Main {

/**
 * @param args
 */
public static void main(String[] args) {

    try {
        Service1 service = new Service1(new URL("http://localhost:8888/Service1.svc?wsdl"), new QName("http://tempuri.org", "Service1"));
        IService1 port = service.getBasicHttpBindingIService1();
        ((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8888/Service1.svc");
        String sFileName = port.hello("Cal");

        System.out.println(sFileName);      


    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

        e.printStackTrace();
    }
}
}

`

The error I'm getting when I attempt to run my application is as follows:

Exception in thread "main" javax.xml.ws.WebServiceException: {http://tempuri.org}Service1 is not a valid service. Valid services are: {http://tempuri.org/}Service1
    at com.sun.xml.ws.client.WSServiceDelegate.(WSServiceDelegate.java:237)
    at com.sun.xml.ws.client.WSServiceDelegate.(WSServiceDelegate.java:182)
    at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:106)
    at javax.xml.ws.Service.(Unknown Source)
    at org.tempuri.Service1.(Service1.java:42)
    at Main.main(Main.java:17)
 

Any assistance with this is appreciated. Thanks.


change:

new QName("http://tempuri.org", "Service1")

to:

new QName("http://tempuri.org/", "Service1")

notice the extra "/" after org.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜