2017-07-14 3 views
0

Ich habe versucht, das Tutorial zu folgen, WCF in einem Android zu integrieren, aber ich habe einen Systemfehler, und ich weiß nicht warum. Kann mir jemand helfen?HelloWorldService WCF antwortet nicht

Ich habe die Firewall deaktiviert und ich habe das Internet auf dem Manifest aktiviert. Ich habe auch versucht, die WCF direkt auf IIS zu hosten, aber ohne irgendeine Verbesserung. Ich habe versucht, die web.config auf der WCF zu ändern, aber ich konnte die Datei nicht erstellen, da ich keinen Silverlight-Endpunkt habe. Ich habe die gleiche IP-Adresse auf dem Android-Emulator

Sie meine WCF appconfig Code unten finden:

<sites>    
<site name="WebSite1" id="1" serverAutoStart="true"> 
    <application path="/">     
     <virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\WebSite1" /> 
    </application>    
    <bindings>     
     <binding protocol="http" bindingInformation=":8080:localhost" /> 
    </bindings>    
</site>    
<site name="PrototypeAWCFHost" id="2"> 
    <application path="/" applicationPool="Clr4IntegratedAppPool"> 
     <virtualDirectory path="/" physicalPath="c:\users\ludovic\documents\visual studio 2015\Projects\PrototypeA\PrototypeAWCFHost" /> 
    </application>     
    <bindings>      
     <binding protocol="http" bindingInformation="*:32195:192.168.1.19" /> 
     <binding protocol="http" bindingInformation="*:6097:localhost" />     
     </bindings>    
</site>    
<site name="HelloWorldWcfHost" id="3"> 
    <application path="/" applicationPool="Clr4IntegratedAppPool"> 
     <virtualDirectory path="/" physicalPath="C:\Users\Ludovic\Documents\Visual Studio 2015\Projects\PrototypeA\HelloWorldWcfHost" /> 
    </application>     
    <bindings> 
     <binding protocol="http" bindingInformation="*:32196:192.168.1.19"/> 
     <binding protocol="http" bindingInformation="*:5082:localhost"/>  
    </bindings>    
</site>    
<siteDefaults> 
    <logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" /> 
    <traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" /> 
    </siteDefaults>    
    <applicationDefaults applicationPool="Clr4IntegratedAppPool" /> 
    <virtualDirectoryDefaults allowSubDirConfig="true" /> 

Meine Android Code unten:

public class MainActivity : Activity 
{ 
    public static readonly EndpointAddress EndPoint = new EndpointAddress("http://192.168.1.19:32196/HelloWorldService.svc"); 

    //private PrototypeAClient _client; 
    private HelloWorldServiceClient _client; 
    private Button _getHelloWorldDataButton; 
    private TextView _getHelloWorldDataTextView; 
    private Button _sayHelloWorldButton; 
    private TextView _sayHelloWorldTextView; 
    protected override void OnCreate(Bundle bundle) 
    { 
    base.OnCreate(bundle); 

    SetContentView(Resource.Layout.Main); 

    InitializeHelloWorldServiceClient(); 

    // This button will invoke the GetHelloWorldData - the method that takes a C# object as a parameter. 
    _getHelloWorldDataButton = FindViewById<Button>(Resource.Id.getHelloWorldDataButton); 
    _getHelloWorldDataButton.Click += GetHelloWorldDataButtonOnClick; 
    _getHelloWorldDataTextView = FindViewById<TextView>(Resource.Id.getHelloWorldDataTextView); 

    // This button will invoke SayHelloWorld - this method takes a simple string as a parameter. 
    _sayHelloWorldButton = FindViewById<Button>(Resource.Id.sayHelloWorldButton); 
    _sayHelloWorldButton.Click += SayHelloWorldButtonOnClick; 
    _sayHelloWorldTextView = FindViewById<TextView>(Resource.Id.sayHelloWorldTextView); 
    } 

    private void InitializeHelloWorldServiceClient() 
    { 
    BasicHttpBinding binding = CreateBasicHttp(); 

    // _client = new PrototypeAClient(binding, EndPoint); 
    _client = new HelloWorldServiceClient(binding, EndPoint); 
    _client.SayHelloToCompleted += ClientOnSayHelloToCompleted; 
    _client.GetHelloDataCompleted += ClientOnGetHelloDataCompleted; 
    } 

    private static BasicHttpBinding CreateBasicHttp() 
    { 
    BasicHttpBinding binding = new BasicHttpBinding 
    { 
     Name = "basicHttpBinding", 
     MaxBufferSize = 2147483645, 
     MaxReceivedMessageSize = 2147483645 
    }; 
    TimeSpan timeout = new TimeSpan(0, 0, 30); 
    binding.SendTimeout = timeout; 
    binding.OpenTimeout = timeout; 
    binding.ReceiveTimeout = timeout; 
    return binding; 
    } 

    private void GetHelloWorldDataButtonOnClick(object sender, EventArgs eventArgs) 
    { 
    //PrototypeAdata data = new PrototypeAdata { Name = "Mr. Chad", SayHello = true }; 
    HelloWorldData data = new HelloWorldData { Name = "Mr. Chad", SayHello = true }; 
    _getHelloWorldDataTextView.Text = "Waiting for WCF..."; 
    _client.GetHelloDataAsync(data); 
    } 

    private void SayHelloWorldButtonOnClick(object sender, EventArgs eventArgs) 
    { 
    _sayHelloWorldTextView.Text = "Waiting for WCF..."; 
    _client.SayHelloToAsync("Kilroy"); 
    } 

    private void ClientOnGetHelloDataCompleted(object sender, GetHelloDataCompletedEventArgs getHelloDataCompletedEventArgs) 
    { 
    string msg = null; 

    if (getHelloDataCompletedEventArgs.Error != null) 
    { 
     msg = getHelloDataCompletedEventArgs.Error.Message; 
    } 
    else if (getHelloDataCompletedEventArgs.Cancelled) 
    { 
     msg = "Request was cancelled."; 
    } 
    else 
    { 
     msg = getHelloDataCompletedEventArgs.Result.Name; 
    } 
    RunOnUiThread(() => _getHelloWorldDataTextView.Text = msg); 
    } 

    private void ClientOnSayHelloToCompleted(object sender, SayHelloToCompletedEventArgs sayHelloToCompletedEventArgs) 
    { 
    string msg = null; 

    if (sayHelloToCompletedEventArgs.Error != null) 
    { 
     msg = sayHelloToCompletedEventArgs.Error.Message; 
    } 
    else if (sayHelloToCompletedEventArgs.Cancelled) 
    { 
     msg = "Request was cancelled."; 
    } 
    else 
    { 
     msg = sayHelloToCompletedEventArgs.Result; 
    } 
    RunOnUiThread(() => _sayHelloWorldTextView.Text = msg); 
    } 
} 

Habe ich etwas verpasst?

Antwort

0

Ich gehe durch den Android-Emulator und nicht durch das Visual Studio Android Emulator und es funktioniert