【问题标题】:HelloWorldService WCF not respondingHelloWorldService WCF 没有响应
【发布时间】:2017-07-14 19:28:19
【问题描述】:

我尝试按照教程将 WCF 包含在 Android 中,但出现系统错误,我不知道为什么。有人可以帮我吗?

我已停用防火墙,并已在清单上激活互联网。 我还尝试直接在 IIS 上托管 WCF,但没有任何改进。我试图修改 WCF 上的 web.config,但我无法创建该文件,因为我没有 silverlight 端点。我在 Android 模拟器上有相同的 IP 地址

你会在下面找到我的 WCF appconfig 代码:

<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" />  

我的Android代码如下:

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

我错过了什么吗?

【问题讨论】:

    标签: c# android wcf xamarin.android


    【解决方案1】:

    我通过 android 模拟器而不是 Visual Studio android 模拟器,它正在工作

    【讨论】:

      猜你喜欢
      • 2021-11-28
      • 1970-01-01
      • 1970-01-01
      • 2022-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-10
      相关资源
      最近更新 更多