0
我试图按照教程在Android中包含WCF,但我有一个系统错误,我不知道为什么。有人能帮我吗?HelloWorldService WCF没有响应
我已经停用了防火墙,并且已经在清单上激活了互联网。 我也尝试在IIS上直接托管WCF,但没有任何改进。我试图修改WCF上的web.config,但我无法创建该文件,因为我没有Silverlight端点。我对Android模拟器
,你会发现我的下面WCF AppConfig的代码相同的IP地址:
<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);
}
}
我错过了什么?