我想弄清楚如何從Windows智能手機中調用WCF服務。我有一個非常簡單的智能手機控制檯應用程序,除了啓動和打電話給服務外,什麼都不做。該服務只是返回一個字符串。我能夠實例化代理類,但是當我調用該方法,它拋出一個異常:不能使用Windows Mobile 5的WCF服務:找不到端點
有沒有終點在 http://mypcname/Service1.svc/basic聽那個 可以接受的消息。這通常是由不正確的地址 或SOAP操作導致的 。有關更多詳細信息,請參見InnerException,如果存在 。
內部異常:
無法建立連接 網絡。
我試着按照this教程來設置windows mobile的服務。
我已經使用NetCFSvcUtil來創建代理類。我在我的機器上的IIS上運行該服務,並讓該Util使用該位置的wsdl。我已經創建了一篇基本的http綁定,正如文章中所建議的,我想我已經指出了正確的uri代理。
這裏有一些相關的代碼段,以防萬一它有助於看到。如果有人有任何建議,我會很感激。我不知道還有什麼我可以戳到讓這個東西工作。
謝謝!
客戶端,(Program.cs中):
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
namespace WcfPoC
{
class Program
{
static void Main(string[] args)
{
try
{
Service1Client proxy = new Service1Client();
string test = proxy.GetData(5);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.InnerException.Message);
Console.WriteLine(e.StackTrace);
}
}
}
}
客戶端代理摘錄(Service1.cs):
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
public partial class Service1Client : Microsoft.Tools.ServiceModel.CFClientBase<IService1>, IService1
{
//modified according to the walk thru linked above...
public static System.ServiceModel.EndpointAddress EndpointAddress = new System.ServiceModel.EndpointAddress("http://boston7/Service1.svc/basic");
/*
*a bunch of code create by the svc util - left unmodified
*/
}
的服務(Service1.svc.cs):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WcfService1
{
// NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file.
public class Service1 : IService1
{
public string GetData(int value) //i'm calling this one...
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}
服務接口(IService1.cs):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WcfService1
{
// NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value); //this is the call im using...
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
/*
* ommitted - not using this type anyway...
*/
}
}
Web.config文件摘錄:
<services>
<service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://boston7/" />
</baseAddresses>
</host>
</service>
</services>
嘿,布賴恩,你有沒有得到WCF在這些工作:審查:移動設備? – jp2code 2013-04-12 20:27:54