面对从android调用wcf服务的问题。 web.config中:
public class fizzbuzz {
private static MouseEvent fizzBuzz() {
String fizz = "Fizz";
String buzz = "Buzz";
String fB = "Fizz buzz";
int num = 0;
while(num <= 100) {
num++;
if (num % 3 == 0 && num % 5 != 0) {
System.out.println (fizz);
}
else if (num % 5 == 0 && num % 3 != 0) {
System.out.println (buzz);
}
else if (num % 3 == 0 && num % 5 == 0){
System.out.println (fB);
}
else {
System.out.println(num);
}
}
return null;
}
public static void ShowGUI(String[] args) {
JPanel displayPanel = new JPanel();
JButton okButton = new JButton("Start count");
okButton.setFont(new Font("Malina Light", Font.TRUETYPE_FONT, 14));
final JLabel Jlab = new JLabel();
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Jlab.getToolTipText(fizzBuzz());
}
});
JPanel content = new JPanel();
content.setLayout(new BorderLayout());
content.add(displayPanel, BorderLayout.CENTER);
content.add(okButton, BorderLayout.SOUTH);
content.add(Jlab, BorderLayout.NORTH);
JFrame window = new JFrame("Gui test");
window.setContentPane(content);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setSize(250, 250);
window.setLocation(100, 100);
window.setVisible(true);;
}
public static void main(String[]args){
//fizzBuzz();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
ShowGUI(args);
}
});
}
IService1.cs
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="httpBehavior">
<webHttp helpEnabled="true" automaticFormatSelectionEnabled="false" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="webBehavior">
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<services>
<service name="GateP.Service1">
<endpoint name="webHttpBinding" address="" binding="webHttpBinding" contract="GateP.IService1" behaviorConfiguration="httpBehavior" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding maxReceivedMessageSize="10000000" receiveTimeout="01:00:00">
<readerQuotas maxStringContentLength="10000000" />
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<defaultDocument>
<files>
<add value="Service1.svc" />
</files>
</defaultDocument>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Service1.svc
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "UserLogin",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
GPUsers UserLogin(GPUsers request);
这是GPUser类
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace GateP
{
public class Service1 : IService1
{
#region GPUser Login
public GPUsers UserLogin(GPUsers request)
{
return request;
}
#endregion
}
}
Android代码(java文件)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Web;
namespace GateP
{
[DataContract]
public class GPUsers
{
[DataMember]
public int userID { get; set; }
[DataMember]
public string username { get; set; }
[DataMember]
public string password { get; set; }
[DataMember]
public string department { get; set; }
[DataMember]
public bool userActive { get; set; }
}
}
到目前为止我尝试了什么: 使用visual studio的文件系统在iis上发布wcf服务。发布后,当我尝试在移动设备和桌面上浏览此地址192.168.5.103:12345时,它看起来很好但是当我使用wcf访问它时,它会抛出状态400,但请求错误。我不知道主要问题是什么。 附上截图请看看。我也在gradle中使用这一行 编译&#39; org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2&#39;