我知道这个问题被多次询问,我已经阅读了所有这些问题,并尝试了所有建议的答案,但没有任何对我有用。 我试图在IIS7 / Windows Server 2008上托管我的WCF服务,我正面临着下面的错误:
public class MainActivity extends AppCompatActivity {
// this is the php file name where to select from the database, the user's phone number
private static final String CHECKPHONENUMBER_URL = "http://www.example.com/myfile.php";
//we are posting phoneNo, which in PHP is phonenumber
public static final String KEY_PHONENUMBER = "phonenumber";
//alContacts is a list of all the phone numbers
public static final ArrayList<String> alContacts = new ArrayList<String>();
Button buttonCheck;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonCheck = (Button) findViewById(R.id.buttonCheck);
//get the names and phone numbers of all contacts in phone book
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
String id = cur.getString(
cur.getColumnIndex(ContactsContract.Contacts._ID));
if (cur.getInt(cur.getColumnIndex(
ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) {
Cursor pCur = cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
new String[]{id}, null);
while (pCur.moveToNext()) {
String phoneNo = pCur.getString(pCur.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
alContacts.add(phoneNo);
// break;
}
pCur.close();
}
}
}
buttonCheck.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
System.out.println("Print the contacts array : ");
System.out.println(alContacts);
CheckifUserisContact();
}
});
}
// send the numbers in one POST to the mySql db with Volley
private void CheckifUserisContact() {
StringRequest stringRequest = new StringRequest(Request.Method.POST, CHECKPHONENUMBER_URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if (response.equals("failure")) {
Toast.makeText(MainActivity.this, "failed", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MainActivity.this, "succeeded", Toast.LENGTH_LONG).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_LONG).show();
}
}) {
//********* HAVING TROUBLE HERE *******************
// JSONObject jsonObject=new JSONObject();
JSONArray jsonArray = new JSONArray();
// jsonObject.put("alContacts",jsonArray);
//for(int i=0;i<=alContacts.size;i++){}
//*****************************************************
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put(KEY_PHONENUMBER, jsonArray.toString());
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
}
我已经运行了命令bellow
HTTP Error 404.3 - Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
应该安装WCF并添加所有必需的MIME类型,但仍然是同样的问题。
此外,我通过执行命令bellow:
确保安装了ASP.NET C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe -i
但仍然是同样的问题。
所以我使用类型application / octet-stream在MIME类型上手动添加.svc,结果是我网站服务的内容:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
有什么建议吗?
答案 0 :(得分:2)
好吧我按照下面的步骤解决了问题:
- 执行以下命令:
cd\Windows\Microsoft.NET\Framework64\v4.0.30319
aspnet_regiis.exe -iru
iisreset
- 打开命令提示符窗口并键入start inetmgr以打开Internet信息服务(IIS)MMC管理单元
- 在左窗格中,展开具有计算机名称的节点,然后展开“网站”节点,然后选择“默认网站”。
- 在功能视图中双击处理程序映射。
- 在应用程序映射列表中,验证.svc文件是否已映射到aspnet_isapi.dll。如果文件尚未映射:
* Click Add Managed Handler.
* Type *.svc into the Request path.
* Type System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 into the Type textbox.
* Type svc-Integrated-4.0 into the Name: textbox.
* Click OK.
* Click Add Script Map.
* Type *.svc into the Request path.
* Type %SystemRoot%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll into the Executable: text box.
* Type svc-ISAPI-2.0 into the Name: text box.
* Click OK.
- 转到模块并删除ServiceModel。