问题描述
嗨
公共接口IHealthPortalLoginService
{
[OperationContract]
[WebInvoke(UriTemplate ="/loging",Method ="POST",RequestFormat = WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json)]
LoginDataContract日志记录(LoginDataContract objlocal);
}
[DataContract]
公共类LoginDataContract
{
#region字段
[DataMember]
public int LoginId {get;放; }
[DataMember]
公共字符串EmailAddress {get;放; }
[DataMember]
公共字符串密码{get;放; }
[DataMember]
public int DoctorId {放; }
[DataMember]
公用字符串Role {get;放; }
[DataMember]
公共布尔IsActive {放; }
[DataMember]
公共DateTime CreatedDate {get;放; }
[DataMember]
公共字符串FavoriteQuestion {get;放; }
[DataMember]
公共字符串答案{get;放; }
[DataMember]
public int状态{放; }
[DataMember]
public int LabId {get;放; }
[DataMember]
public int FrontdeskId {获取;放; }
#endregion
}
Web.config
< pre lang ="xml">& lt;?xml version =& quot; 1.0& quot;?& gt;
& lt;配置& gt;
& lt; appSettings& gt;
& lt;添加密钥=&"DBProviderType&"值=&"1"/& gt;
密码= PGI123;池= true&"/& gt;
& lt;/appSettings& gt;
& lt; system.web& gt;
& lt; httpRuntime maxRequestLength =& quot; 10000000& quot;/& gt;
& lt; compilation debug =& quot; true& quot;/& gt;
& lt//system.web& gt;
& lt;!-部署服务库项目时,必须将配置文件的内容添加到主机的
app.config文件. System.Configuration不支持库的配置文件. -& gt;
& lt; system.serviceModel& gt;
& lt; serviceHostingEnvironment multipleSiteBindingsEnabled =&"true&" /& gt;
& lt;服务& gt;
& lt;服务名称=& quot; WcfContact.Service1& quot; behaviorConfiguration =&"httpBehaviour&"& gt;
& lt;端点地址=& quot;& quot; binding =&"webHttpBinding&" contract =& quot; WcfContact.IService1& quot; behaviorConfiguration =&"httpEndpointBehaviour&" & gt;
& lt; identity& gt;
& lt; dns value =&本地主机& quot;/& gt;
& lt//identity& gt;
& lt//endpoint& gt;
<端点地址=&"mex&" binding =& quot; mexHttpBinding& quot; contract =&"IMetadataExchange&"/& gt;
& lt//service& gt;
& lt;服务名称=& quot; WcfContact.HealthPortalLoginService& quot; behaviorConfiguration =&"httpBehaviour&"& gt;
& lt;端点地址=& quot;& quot; binding =&"webHttpBinding&"合同=" WcfContact.IHealthPortalLoginService" behaviorConfiguration =&"httpEndpointBehaviour&"& gt;
& lt; identity& gt;
& lt; dns value =&本地主机& quot;/& gt;
& lt//identity& gt;
& lt//endpoint& gt;
<端点地址=&"mex&" binding =& quot; mexHttpBinding& quot; contract =&"IMetadataExchange&"/& gt;
& lt//service& gt;
& lt//services& gt;
& lt !!-& lt; bindings& gt;
& lt; webHttpBinding& gt;
& lt;绑定名称=&"StreamedRequestWebBinding&"
BypassProxyOnLocal =& quot; true& quot;
useDefaultWebProxy =& quot; false& quot;
hostNameComparisonMode =&"WeakWildcard&";
sendTimeout =& quot; 00:05:00& quot;
openTimeout =& quot; 00:05:00& quot;
receiveTimeout =& quot; 00:05:00& quot;
maxReceivedMessageSize =&"2147483647&"
maxBufferSize =&"2147483647&"
maxBufferPoolSize =&"2147483647&"
transferMode =&"StreamedRequest& gt;"
& lt; readerQuotas maxArrayLength =& quot; 2147483647& quot;
maxStringContentLength =&"2147483647&"/>
& lt//binding& gt;
& lt//webHttpBinding& gt;
& lt;/bindings& gt-& gt;
& lt;行为& gt;
& lt; endpointBehaviors& gt;
& lt !!-& lt;行为名称=& quot; jsonBehavior& quot;>
& lt; enableWebScript/& gt;
& lt//behavior& gt .--& gt;
& lt;行为名称=&"httpEndpointBehaviour& quot;"& gt;
& lt; webHttp/& gt;
& lt//behavior& gt;
& lt//endpointBehaviors& gt;
& lt; serviceBehaviors& gt;
& lt;行为名称=&"httpBehaviour& quot;<
& lt; serviceMetadata httpGetEnabled =&"true& quot; /& gt;
& lt; serviceDebug includeExceptionDetailInFaults =&"false&" /& gt;
& lt//behavior& gt;
& lt;行为名称=&&"& gt;
& lt; serviceMetadata httpGetEnabled =&"true& quot; /& gt;
& lt; serviceDebug includeExceptionDetailInFaults =&"false&" /& gt;
& lt//behavior& gt;
& lt;/serviceBehaviors& gt;
& lt//behaviors& gt;
& lt//system.serviceModel& gt;
& lt;启动& gt;
& lt; supportedRuntime version =& quot; v4.0& quot; sku =&.NETFramework,Version = v4.0&"/& gt;
& lt;/startup& gt;
& lt;/configuration& gt;</pre>
我可以从C#应用程序中使用该服务
HttpWebRequest请求=(HttpWebRequest)WebRequest.Create("http://xx.xx.xx.xx/ContactService/HealthPortalLoginService.svc/loging");
request.Method ="POST";
request.ContentType = @"application/json; charset = utf-8";
LoginDataContract local =新的LoginDataContract();
local.EmailAddress ="[email protected]";
local.Password =克里希纳";
local.CreatedDate = DateTime.UtcNow;
DataContractJsonSerializer jsonser = new DataContractJsonSerializer(typeof(LoginDataContract));
MemoryStream ms =新的MemoryStream();
jsonser.WriteObject(ms,local);
字符串json = Encoding.Default.GetString(ms.ToArray());
request.ContentLength = Encoding.UTF8.GetByteCount(json.ToString());
使用(Stream stream = request.GetRequestStream())
{
stream.Write(Encoding.UTF8.GetBytes(json.ToString()),0,Encoding.UTF8.GetByteCount(json.ToString()));
}
HttpWebResponse response = request.GetResponse()as HttpWebResponse;
流respStream = response.GetResponseStream();
如果(respStream!= null)
{
//lbl.Text = new StreamReader(respStream).ReadToEnd();
LoginDataContract p2 =(LoginDataContract)jsonser.ReadObject(respStream);
}
我的C#代码正在使用服务很好,
问题是,我的ipad开发人员无法使用我的服务,代码中是否有任何问题...
Hi
public interface IHealthPortalLoginService
{
[OperationContract]
[WebInvoke(UriTemplate = "/loging",Method="POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
LoginDataContract loging(LoginDataContract objlocal);
}
[DataContract]
public class LoginDataContract
{
#region Fields
[DataMember]
public int LoginId { get; set; }
[DataMember]
public string EmailAddress { get; set; }
[DataMember]
public string Password { get; set; }
[DataMember]
public int DoctorId { get; set; }
[DataMember]
public string Role { get; set; }
[DataMember]
public bool IsActive { get; set; }
[DataMember]
public DateTime CreatedDate { get; set; }
[DataMember]
public string FavoriteQuestion { get; set; }
[DataMember]
public string Answer { get; set; }
[DataMember]
public int Status { get; set; }
[DataMember]
public int LabId { get; set; }
[DataMember]
public int FrontdeskId { get; set; }
#endregion
}
Web.config
<pre lang="xml"><?xml version="1.0"?>
<configuration>
<appSettings>
<add key="DBProviderType" value="1"/>
Password=PGI123;Pooling=true"/>
</appSettings>
<system.web>
<httpRuntime maxRequestLength="10000000"/>
<compilation debug="true"/>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host''s
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="WcfContact.Service1" behaviorConfiguration="httpBehaviour">
<endpoint address="" binding="webHttpBinding" contract="WcfContact.IService1" behaviorConfiguration="httpEndpointBehaviour" >
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<service name="WcfContact.HealthPortalLoginService" behaviorConfiguration="httpBehaviour">
<endpoint address="" binding="webHttpBinding" contract="WcfContact.IHealthPortalLoginService" behaviorConfiguration="httpEndpointBehaviour">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<!--<bindings>
<webHttpBinding>
<binding name="StreamedRequestWebBinding"
bypassProxyOnLocal="true"
useDefaultWebProxy="false"
hostNameComparisonMode="WeakWildcard"
sendTimeout="00:05:00"
openTimeout="00:05:00"
receiveTimeout="00:05:00"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
transferMode="StreamedRequest">
<readerQuotas maxArrayLength="2147483647"
maxStringContentLength="2147483647"/>
</binding>
</webHttpBinding>
</bindings>-->
<behaviors>
<endpointBehaviors>
<!--<behavior name="jsonBehavior">
<enableWebScript/>
</behavior>-->
<behavior name="httpEndpointBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="httpBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration></pre>
i can consume the service from c# app
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://xx.xx.xx.xx/ContactService/HealthPortalLoginService.svc/loging");
request.Method = "POST";
request.ContentType = @"application/json; charset=utf-8";
LoginDataContract local = new LoginDataContract();
local.EmailAddress = "[email protected]";
local.Password = "krishna";
local.CreatedDate = DateTime.UtcNow;
DataContractJsonSerializer jsonser = new DataContractJsonSerializer(typeof(LoginDataContract));
MemoryStream ms = new MemoryStream();
jsonser.WriteObject(ms, local);
string json = Encoding.Default.GetString(ms.ToArray());
request.ContentLength = Encoding.UTF8.GetByteCount(json.ToString());
using (Stream stream = request.GetRequestStream())
{
stream.Write(Encoding.UTF8.GetBytes(json.ToString()), 0, Encoding.UTF8.GetByteCount(json.ToString()));
}
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream respStream = response.GetResponseStream();
if (respStream != null)
{
//lbl.Text = new StreamReader(respStream).ReadToEnd();
LoginDataContract p2 = (LoginDataContract)jsonser.ReadObject(respStream);
}
its fine that my c# code is consuming the service
Problem is ,my ipad developer cant consume my service , is ther any problem in my code...
推荐答案
这篇关于消费wcf休息服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!