2017-02-01 9 views
0

私はアンドロイドデベロッパーです。私はsoapを使用してWCF WebサービスからXML応答をフェッチするアンドロイドアプリケーションを作成したいと思います。 WCF Webサービスを作成しました.WCF Webサービスは、XMLドキュメントを取り出し、そのドキュメントのコンテンツを返します。ここで私はどのようにアンドロイドでそのコンテンツを消費するか分からない。さらに、私はWCFを初めて熟知しており、私が正しいか間違っているかどうか混乱しています。どんな助けもありがとう。wcf Webサービスを作成してandroidでxml応答を返す

IService.cs

namespace WcfXML 
{ 

[ServiceContract (Namespace="http://tempuri.org/")] 
public interface IService1 
{ 

    [OperationContract, XmlSerializerFormat] 
    XmlElement GetData(); 
} 
} 

Service1.svc

namespace WcfXML 
{ 

public class Service1 : IService1 
{ 
    public XmlElement GetData() 
    { 
     XmlDocument xmlDoc = new XmlDocument(); 
     xmlDoc.Load(@"D:\defaultGraphProperties.xml"); 
     return xmlDoc.DocumentElement; 
    } 
} 
} 

私は(F5)を実行すると、これを作成した後、私は、メソッドを呼び出すことはできませんよ。このWebサービスをAndroidでどのように使用できますか?助けてください!!!!

答えて

0

webHttpBindingの設定をの下にweb.configに追加する必要があります。

次にあなたがブラウザからのWCFサービスを消費することができるようになりますweb.configでこの変更を行った後<System.serviceModel>

 <services> 
      <service name="Test_WcfService.Service1" behaviorConfiguration="ServiceBehavior"> 
      <endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpBindingConfiguration" behaviorConfiguration="web" contract="Test_WcfService.IService1"></endpoint> 
      <endpoint address="Service1.svc" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfiguration" contract="Test_WcfService.IService1"></endpoint> 
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint> 
      </service> 
     </services> 
     <bindings> 
      <webHttpBinding> 
      <binding name="webHttpBindingConfiguration" maxReceivedMessageSize="2147483647" /> 
      </webHttpBinding> 
      <basicHttpBinding> 
      <binding name="basicHttpBindingConfiguration" maxReceivedMessageSize="2147483647" /> 
      </basicHttpBinding> 
     </bindings> 
     <behaviors> 
      <serviceBehaviors> 
      <behavior name="ServiceBehavior"> 
       <!-- To avoid disclosing metadata information, set the values below to false before deployment --> 
       <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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> 
      <endpointBehaviors> 
      <behavior name="web"> 
       <webHttp /> 
      </behavior> 
      </endpointBehaviors> 
     </behaviors> 

web.configで以下のコードを追加します。

Test_WcfService.Service1およびTest_WcfService.IService1をWCFサービス名とインターフェイスに置き換えます。

WCFサービスを使用するには、AndroidからSoap Requestを行う必要があります。

デモwcfサービスを共有する場合は、私の最後に必要な構成変更を行います。

+0

助けてくれてありがとう!私は管理者としてVS2012を使いました。私は消費し、デバッグを行い、XMLファイルを取得して返すことができました。しかし、ローカルWebサービスはローカルホストにあります。ローカルホストとの接続方法 – Nair123

+0

okどのネットワークがアンドロイドデバイスに接続されていますか。あなたのAndroidデバイスがwebserviceが実行されているネットワークに接続されている場合、あなたのPCのIPアドレスを使用してwcfサービスを使用できます。 –

関連する問題