[英]WCF Webservices in visual studio
我是新來的,需要一些幫助。 我已經在Visual Studio中創建了一個wcf服務應用程序,並編寫了一種簡單的登錄方法,該方法將接收參數userid和password,然后返回已記錄用戶對象的對象,該對象具有兩個字段名稱和組織。
LoggedUser類別:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
namespace crmpp_android_service
{
public class LoggedUser
{
public string name;
public string organization;
[DataMember]
public string Name
{
get { return name; }
set { name = value; }
}
[DataMember]
public string Organization
{
get { return organization; }
set { organization = value; }
}
}
}
運營合同:
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
UriTemplate = "login/?userid={userid} & pass={pass}"
)]
[Description("User Login return username & Organization currently affiliated")]
LoggedUser login(string userid, string pass);
Service1.svc中的方法實現:
public LoggedUser login(string userid , string pass)
{
LoggedUser log_usr = new LoggedUser();
log_usr.name = "Ahsan Mehdi";
log_usr.organization = "JDC";
return log_usr;
}
但是,當我通過按ctrl + F5鍵運行應用程序時,它會像這樣打開一個wcf測試客戶端並返回數據。
當我編寫服務URL時,我無法從Android應用程序或僅從瀏覽器獲得響應,它向我顯示了這樣的頁面。
http://localhost:57127/Service1.svc
並在這樣的完整網址時
http://localhost:57127/Service1.svc/login/?userid=abc123&pass123
它不返回任何指南或幫助,請盡快返回。
據我了解,您想訪問此WCF URL,該URL托管在您的本地主機上而不是IIS上。 要訪問您的本地主機Web服務,請使用此主機(而不是本地主機)
http://10.0.2.2:Port/Service1.svc/login/?userid=abc123&pass123
在IIS上,使用分配給您的系統IP。
http://192.168.0.123:Port/Service1.svc/login/?userid=abc123&pass123
我希望這會清除您有關連接到android項目的問題。
獲取WCFstorm。 運行它時,添加一個新服務,然后復制該服務的網址(在屏幕快照中,顯示為:
localhost:57127/Service.svc
這樣就可以測試服務了。
這就是我在測試WCF服務時使用的方法。
我使用的另一個工具是Fiddler。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.