Eclipseで、C#で書かれたWCF Webサービスを参照する簡単なJavaコンソールアプリケーションを作成しました。私のPCでWCFサービスをローカルにホストすると、Javaクライアントを使用してサービスに接続できません。Java AppをWCF Webサービスに接続する際のエラー
文字列IService1.Hello(文字列SNAME) を:
は次のエンドポイントを持つ 'Service1.svc' を作成し、以下のように
私はWCFサービスを作成するために撮影したステップがあります{ "Hello" + sName + "!"を返します。 ; }
次のようにサービスの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"/>
サービスは常にポート8888
を使用しますので、私はプロパティを変更
私はサービスをテストしましたC#コンソールアプリケーションを起動します。
Javaクライアントを作成するには、私は次のようでした:
ダウンロードおよびメトロ(Webサーバー)にバンドルGlassfishの3.0.1(アプリケーションサーバ)をインストール
Javaクライアントアプリケーションのサービス参照コードを生成するには、jdkのbinディレクトリにある 'wsimport'ツールを使用します。
上記の手順2のコードをEclipseの新しい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();
}
}
}
`
エラー私がしようとしたとき、私は取得していますが、次のようにWebサービスを呼び出して、私のコンソールアプリで新しいJavaクラスを作成します。私のアプリケーションを実行するには、次のように:
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)
これについての助けに感謝します。ありがとう。
名前空間定義の後に/があり、もう一方が名前空間定義の後にあるということはありますか? JavaクライアントのQNameに/を追加してみてください。 – Wysawyg