0

C#で記述されたWCFWebサービスを参照する単純なJavaコンソールアプリケーションをEclipseで記述しました。PCでローカルにWCFサービスをホストしているため、Javaクライアントを使用してサービスに接続できません。

WCFサービスを作成するために行った手順は次のとおりです

  1. 次のエンドポイントで「Service1.svc」を作成します。

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

  2. サービスのWeb構成は次のとおりです。

      <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>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    


  3. サービスが常にポート8888を使用するように、プロパティを変更しました。

  4. C#コンソールアプリケーションを使用してサービスをテストしました。

Javaクライアントを作成するために、次のことを行いました。

  1. Metro(Webサーバー)にバンドルされているGlassfish 3.0.1(アプリケーションサーバー)をダウンロードしてインストールします

  2. jdkの「bin」ディレクトリにある「wsimport」ツールを使用して、Javaクライアントアプリのサービス参照コードを生成します。サービス参照を作成するために実行した.batファイル

  3. 上記のステップ2のコードをEclipseの新しいJavaアプリケーションにコピーします。

  4. 次のようにWebサービスを呼び出すコンソールアプリで新しいJavaクラスを作成します

`

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();
    }
}
}

`

アプリケーションを実行しようとしたときに発生するエラーは次のとおりです。

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)
 

これに関する支援は大歓迎です。ありがとう。

4

1 に答える 1

1

変化する:

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

に:

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

組織の後に余分な「/」があることに注意してください。

于 2010-12-15T19:31:40.913 に答える